| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/offline_pages/prerendering_loader.h" | 5 #include "chrome/browser/android/offline_pages/prerendering_loader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 PrerenderingLoaderTest::PrerenderingLoaderTest() | 142 PrerenderingLoaderTest::PrerenderingLoaderTest() |
| 143 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 143 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 144 callback_load_status_(Offliner::RequestStatus::UNKNOWN) {} | 144 callback_load_status_(Offliner::RequestStatus::UNKNOWN) {} |
| 145 | 145 |
| 146 void PrerenderingLoaderTest::SetUp() { | 146 void PrerenderingLoaderTest::SetUp() { |
| 147 loader_.reset(new PrerenderingLoader(&profile_)); | 147 loader_.reset(new PrerenderingLoader(&profile_)); |
| 148 test_adapter_ = new TestAdapter(loader_.get()); | 148 test_adapter_ = new TestAdapter(loader_.get()); |
| 149 loader_->SetAdapterForTesting(base::WrapUnique(test_adapter_)); | 149 loader_->SetAdapterForTesting(base::WrapUnique(test_adapter_)); |
| 150 callback_called_ = false; |
| 150 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 151 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 151 } | 152 } |
| 152 | 153 |
| 153 void PrerenderingLoaderTest::OnLoadDone(Offliner::RequestStatus load_status, | 154 void PrerenderingLoaderTest::OnLoadDone(Offliner::RequestStatus load_status, |
| 154 content::WebContents* web_contents) { | 155 content::WebContents* web_contents) { |
| 155 callback_called_ = true; | 156 callback_called_ = true; |
| 156 callback_load_status_ = load_status; | 157 callback_load_status_ = load_status; |
| 157 } | 158 } |
| 158 | 159 |
| 159 TEST_F(PrerenderingLoaderTest, CanPrerender) { | 160 TEST_F(PrerenderingLoaderTest, CanPrerender) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 EXPECT_TRUE(callback_called()); | 246 EXPECT_TRUE(callback_called()); |
| 246 // We did not provide any WebContents for the callback so expect did not load. | 247 // We did not provide any WebContents for the callback so expect did not load. |
| 247 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED, | 248 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED, |
| 248 callback_load_status()); | 249 callback_load_status()); |
| 249 | 250 |
| 250 // Stopped event causes no harm. | 251 // Stopped event causes no harm. |
| 251 test_adapter()->GetObserver()->OnPrerenderStop(); | 252 test_adapter()->GetObserver()->OnPrerenderStop(); |
| 252 PumpLoop(); | 253 PumpLoop(); |
| 253 } | 254 } |
| 254 | 255 |
| 256 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedUnsupportedScheme) { |
| 257 test_adapter()->Configure( |
| 258 nullptr /* web_contents */, |
| 259 prerender::FinalStatus::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 260 GURL gurl("http://testit.sea"); |
| 261 EXPECT_TRUE(loader()->IsIdle()); |
| 262 EXPECT_TRUE(loader()->LoadPage( |
| 263 gurl, |
| 264 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); |
| 265 EXPECT_FALSE(loader()->IsIdle()); |
| 266 EXPECT_FALSE(loader()->IsLoaded()); |
| 267 |
| 268 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded(); |
| 269 PumpLoop(); |
| 270 EXPECT_TRUE(loader()->IsIdle()); |
| 271 EXPECT_TRUE(callback_called()); |
| 272 // Unsupported Scheme final status currently considered a cancel rather |
| 273 // than failure in case it is due to lost network connectivity. |
| 274 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED, |
| 275 callback_load_status()); |
| 276 |
| 277 // Stopped event causes no harm. |
| 278 test_adapter()->GetObserver()->OnPrerenderStop(); |
| 279 PumpLoop(); |
| 280 } |
| 281 |
| 255 TEST_F(PrerenderingLoaderTest, LoadPageLoadCanceledFromStopLoading) { | 282 TEST_F(PrerenderingLoaderTest, LoadPageLoadCanceledFromStopLoading) { |
| 256 GURL gurl("http://testit.sea"); | 283 GURL gurl("http://testit.sea"); |
| 257 EXPECT_TRUE(loader()->IsIdle()); | 284 EXPECT_TRUE(loader()->IsIdle()); |
| 258 EXPECT_TRUE(loader()->LoadPage( | 285 EXPECT_TRUE(loader()->LoadPage( |
| 259 gurl, | 286 gurl, |
| 260 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); | 287 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); |
| 261 EXPECT_FALSE(loader()->IsIdle()); | 288 EXPECT_FALSE(loader()->IsIdle()); |
| 262 EXPECT_FALSE(loader()->IsLoaded()); | 289 EXPECT_FALSE(loader()->IsLoaded()); |
| 263 | 290 |
| 264 loader()->StopLoading(); | 291 loader()->StopLoading(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 287 test_adapter()->Disable(); | 314 test_adapter()->Disable(); |
| 288 GURL gurl("http://testit.sea"); | 315 GURL gurl("http://testit.sea"); |
| 289 EXPECT_TRUE(loader()->IsIdle()); | 316 EXPECT_TRUE(loader()->IsIdle()); |
| 290 EXPECT_FALSE(loader()->LoadPage( | 317 EXPECT_FALSE(loader()->LoadPage( |
| 291 gurl, | 318 gurl, |
| 292 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); | 319 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); |
| 293 EXPECT_TRUE(loader()->IsIdle()); | 320 EXPECT_TRUE(loader()->IsIdle()); |
| 294 } | 321 } |
| 295 | 322 |
| 296 } // namespace offline_pages | 323 } // namespace offline_pages |
| OLD | NEW |