Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Side by Side Diff: chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher_browsertest.cc

Issue 48713008: [sync] Allow FakeURLFetcher to return arbitrary HTTP response codes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "content/public/test/test_utils.h" 11 #include "content/public/test/test_utils.h"
12 #include "net/http/http_status_code.h"
12 #include "net/url_request/test_url_fetcher_factory.h" 13 #include "net/url_request/test_url_fetcher_factory.h"
13 #include "net/url_request/url_fetcher.h" 14 #include "net/url_request/url_fetcher.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "ui/gfx/codec/png_codec.h" 17 #include "ui/gfx/codec/png_codec.h"
17 #include "ui/gfx/size.h" 18 #include "ui/gfx/size.h"
18 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
19 20
20 namespace { 21 namespace {
21 const bool kAsyncCall = true; 22 const bool kAsyncCall = true;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 ASSERT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(image, true, &compressed)); 98 ASSERT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(image, true, &compressed));
98 99
99 // Copy the bits into the string, and put them into the FakeURLFetcher. 100 // Copy the bits into the string, and put them into the FakeURLFetcher.
100 std::string image_string(compressed.begin(), compressed.end()); 101 std::string image_string(compressed.begin(), compressed.end());
101 102
102 // Set up a delegate to wait for the callback. 103 // Set up a delegate to wait for the callback.
103 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); 104 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall);
104 105
105 NotificationBitmapFetcher fetcher(url, &delegate); 106 NotificationBitmapFetcher fetcher(url, &delegate);
106 107
107 url_fetcher_factory_->SetFakeResponse(url, image_string, true); 108 url_fetcher_factory_->SetFakeResponse(url, image_string, net::HTTP_OK);
108 109
109 // We expect that the image decoder will get called and return 110 // We expect that the image decoder will get called and return
110 // an image in a callback to OnImageDecoded(). 111 // an image in a callback to OnImageDecoded().
111 fetcher.Start(browser()->profile()); 112 fetcher.Start(browser()->profile());
112 113
113 // Blocks until test delegate is notified via a callback. 114 // Blocks until test delegate is notified via a callback.
114 content::RunMessageLoop(); 115 content::RunMessageLoop();
115 116
116 ASSERT_TRUE(delegate.success()); 117 ASSERT_TRUE(delegate.success());
117 118
(...skipping 29 matching lines...) Expand all
147 OnURLFetchFailureTest) { 148 OnURLFetchFailureTest) {
148 GURL url("http://example.com/this-should-be-fetch-failure"); 149 GURL url("http://example.com/this-should-be-fetch-failure");
149 150
150 // We intentionally put no data into the bitmap to simulate a failure. 151 // We intentionally put no data into the bitmap to simulate a failure.
151 152
152 // Set up a delegate to wait for the callback. 153 // Set up a delegate to wait for the callback.
153 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); 154 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall);
154 155
155 NotificationBitmapFetcher fetcher(url, &delegate); 156 NotificationBitmapFetcher fetcher(url, &delegate);
156 157
157 url_fetcher_factory_->SetFakeResponse(url, std::string(), false); 158 url_fetcher_factory_->SetFakeResponse(url,
159 std::string(),
160 net::HTTP_INTERNAL_SERVER_ERROR);
158 161
159 fetcher.Start(browser()->profile()); 162 fetcher.Start(browser()->profile());
160 163
161 // Blocks until test delegate is notified via a callback. 164 // Blocks until test delegate is notified via a callback.
162 content::RunMessageLoop(); 165 content::RunMessageLoop();
163 166
164 EXPECT_FALSE(delegate.success()); 167 EXPECT_FALSE(delegate.success());
165 } 168 }
166 169
167 IN_PROC_BROWSER_TEST_F(NotificationBitmapFetcherBrowserTest, 170 IN_PROC_BROWSER_TEST_F(NotificationBitmapFetcherBrowserTest,
168 HandleImageFailedTest) { 171 HandleImageFailedTest) {
169 GURL url("http://example.com/this-should-be-a-decode-failure"); 172 GURL url("http://example.com/this-should-be-a-decode-failure");
170 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); 173 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall);
171 NotificationBitmapFetcher fetcher(url, &delegate); 174 NotificationBitmapFetcher fetcher(url, &delegate);
172 url_fetcher_factory_->SetFakeResponse( 175 url_fetcher_factory_->SetFakeResponse(
173 url, std::string("Not a real bitmap"), true); 176 url, std::string("Not a real bitmap"), net::HTTP_OK);
174 177
175 fetcher.Start(browser()->profile()); 178 fetcher.Start(browser()->profile());
176 179
177 // Blocks until test delegate is notified via a callback. 180 // Blocks until test delegate is notified via a callback.
178 content::RunMessageLoop(); 181 content::RunMessageLoop();
179 182
180 EXPECT_FALSE(delegate.success()); 183 EXPECT_FALSE(delegate.success());
181 } 184 }
182 185
183 } // namespace notifier 186 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698