| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher
     .h" | 5 #include "chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher
     .h" | 
| 6 | 6 | 
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" | 
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" | 
| 9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" | 
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 97   ASSERT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(image, true, &compressed)); | 97   ASSERT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(image, true, &compressed)); | 
| 98 | 98 | 
| 99   // Copy the bits into the string, and put them into the FakeURLFetcher. | 99   // Copy the bits into the string, and put them into the FakeURLFetcher. | 
| 100   std::string image_string(compressed.begin(), compressed.end()); | 100   std::string image_string(compressed.begin(), compressed.end()); | 
| 101 | 101 | 
| 102   // Set up a delegate to wait for the callback. | 102   // Set up a delegate to wait for the callback. | 
| 103   NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 103   NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 
| 104 | 104 | 
| 105   NotificationBitmapFetcher fetcher(url, &delegate); | 105   NotificationBitmapFetcher fetcher(url, &delegate); | 
| 106 | 106 | 
| 107   url_fetcher_factory_->SetFakeResponse(url.spec(), image_string, true); | 107   url_fetcher_factory_->SetFakeResponse(url, image_string, true); | 
| 108 | 108 | 
| 109   // We expect that the image decoder will get called and return | 109   // We expect that the image decoder will get called and return | 
| 110   // an image in a callback to OnImageDecoded(). | 110   // an image in a callback to OnImageDecoded(). | 
| 111   fetcher.Start(browser()->profile()); | 111   fetcher.Start(browser()->profile()); | 
| 112 | 112 | 
| 113   // Blocks until test delegate is notified via a callback. | 113   // Blocks until test delegate is notified via a callback. | 
| 114   content::RunMessageLoop(); | 114   content::RunMessageLoop(); | 
| 115 | 115 | 
| 116   ASSERT_TRUE(delegate.success()); | 116   ASSERT_TRUE(delegate.success()); | 
| 117 | 117 | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 147                        OnURLFetchFailureTest) { | 147                        OnURLFetchFailureTest) { | 
| 148   GURL url("http://example.com/this-should-be-fetch-failure"); | 148   GURL url("http://example.com/this-should-be-fetch-failure"); | 
| 149 | 149 | 
| 150   // We intentionally put no data into the bitmap to simulate a failure. | 150   // We intentionally put no data into the bitmap to simulate a failure. | 
| 151 | 151 | 
| 152   // Set up a delegate to wait for the callback. | 152   // Set up a delegate to wait for the callback. | 
| 153   NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 153   NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 
| 154 | 154 | 
| 155   NotificationBitmapFetcher fetcher(url, &delegate); | 155   NotificationBitmapFetcher fetcher(url, &delegate); | 
| 156 | 156 | 
| 157   url_fetcher_factory_->SetFakeResponse(url.spec(), std::string(), false); | 157   url_fetcher_factory_->SetFakeResponse(url, std::string(), false); | 
| 158 | 158 | 
| 159   fetcher.Start(browser()->profile()); | 159   fetcher.Start(browser()->profile()); | 
| 160 | 160 | 
| 161   // Blocks until test delegate is notified via a callback. | 161   // Blocks until test delegate is notified via a callback. | 
| 162   content::RunMessageLoop(); | 162   content::RunMessageLoop(); | 
| 163 | 163 | 
| 164   EXPECT_FALSE(delegate.success()); | 164   EXPECT_FALSE(delegate.success()); | 
| 165 } | 165 } | 
| 166 | 166 | 
| 167 IN_PROC_BROWSER_TEST_F(NotificationBitmapFetcherBrowserTest, | 167 IN_PROC_BROWSER_TEST_F(NotificationBitmapFetcherBrowserTest, | 
| 168                        HandleImageFailedTest) { | 168                        HandleImageFailedTest) { | 
| 169   GURL url("http://example.com/this-should-be-a-decode-failure"); | 169   GURL url("http://example.com/this-should-be-a-decode-failure"); | 
| 170   NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 170   NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 
| 171   NotificationBitmapFetcher fetcher(url, &delegate); | 171   NotificationBitmapFetcher fetcher(url, &delegate); | 
| 172   url_fetcher_factory_->SetFakeResponse( | 172   url_fetcher_factory_->SetFakeResponse( | 
| 173       url.spec(), std::string("Not a real bitmap"), true); | 173       url, std::string("Not a real bitmap"), true); | 
| 174 | 174 | 
| 175   fetcher.Start(browser()->profile()); | 175   fetcher.Start(browser()->profile()); | 
| 176 | 176 | 
| 177   // Blocks until test delegate is notified via a callback. | 177   // Blocks until test delegate is notified via a callback. | 
| 178   content::RunMessageLoop(); | 178   content::RunMessageLoop(); | 
| 179 | 179 | 
| 180   EXPECT_FALSE(delegate.success()); | 180   EXPECT_FALSE(delegate.success()); | 
| 181 } | 181 } | 
| 182 | 182 | 
| 183 }  // namespace notifier | 183 }  // namespace notifier | 
| OLD | NEW | 
|---|