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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_loader_unittest.cc

Issue 2333333002: [Offline Pages] Fixes PrerenderingLoader bug to clear session_contents_ when PrerenderManager does … (Closed)
Patch Set: Update per dewittj feedback Created 4 years, 3 months 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
« no previous file with comments | « chrome/browser/android/offline_pages/prerendering_loader.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "content/public/test/web_contents_tester.h" 14 #include "content/public/test/web_contents_tester.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace offline_pages { 17 namespace offline_pages {
18 18
19 namespace { 19 namespace {
20 20
21 // Adapter that intercepts prerender stack calls for testing. 21 // Adapter that intercepts prerender stack calls for testing.
22 class TestAdapter : public PrerenderAdapter { 22 class TestAdapter : public PrerenderAdapter {
23 public: 23 public:
24 explicit TestAdapter(PrerenderAdapter::Observer* observer) 24 explicit TestAdapter(PrerenderAdapter::Observer* observer)
25 : PrerenderAdapter(observer), 25 : PrerenderAdapter(observer),
26 active_(false), 26 active_(false),
27 disabled_(false), 27 disabled_(false),
28 fail_start_(false),
28 observer_(observer), 29 observer_(observer),
29 web_contents_(nullptr), 30 web_contents_(nullptr),
30 final_status_(prerender::FinalStatus::FINAL_STATUS_MAX) {} 31 final_status_(prerender::FinalStatus::FINAL_STATUS_MAX) {}
31 ~TestAdapter() override {} 32 ~TestAdapter() override {}
32 33
33 // PrerenderAdapter implementation. 34 // PrerenderAdapter implementation.
34 bool CanPrerender() const override; 35 bool CanPrerender() const override;
35 bool StartPrerender( 36 bool StartPrerender(
36 content::BrowserContext* browser_context, 37 content::BrowserContext* browser_context,
37 const GURL& url, 38 const GURL& url,
38 content::SessionStorageNamespace* session_storage_namespace, 39 content::SessionStorageNamespace* session_storage_namespace,
39 const gfx::Size& size) override; 40 const gfx::Size& size) override;
40 content::WebContents* GetWebContents() const override; 41 content::WebContents* GetWebContents() const override;
41 prerender::FinalStatus GetFinalStatus() const override; 42 prerender::FinalStatus GetFinalStatus() const override;
42 bool IsActive() const override; 43 bool IsActive() const override;
43 void DestroyActive() override; 44 void DestroyActive() override;
44 45
45 // Sets prerendering to be disabled. This will cause the CanPrerender() 46 // Sets prerendering to be disabled. This will cause the CanPrerender()
46 // to return false. 47 // to return false.
47 void Disable(); 48 void Disable();
48 49
50 // Sets prerendering to fail start prerender requests.
51 void FailStart();
52
49 // Configures mocked prerendering details. 53 // Configures mocked prerendering details.
50 void Configure(content::WebContents* web_contents, 54 void Configure(content::WebContents* web_contents,
51 prerender::FinalStatus final_status); 55 prerender::FinalStatus final_status);
52 56
53 // Returns the observer for test access. 57 // Returns the observer for test access.
54 PrerenderAdapter::Observer* GetObserver() const { return observer_; } 58 PrerenderAdapter::Observer* GetObserver() const { return observer_; }
55 59
56 private: 60 private:
57 bool active_; 61 bool active_;
58 bool disabled_; 62 bool disabled_;
63 bool fail_start_;
59 PrerenderAdapter::Observer* observer_; 64 PrerenderAdapter::Observer* observer_;
60 content::WebContents* web_contents_; 65 content::WebContents* web_contents_;
61 prerender::FinalStatus final_status_; 66 prerender::FinalStatus final_status_;
62 67
63 DISALLOW_COPY_AND_ASSIGN(TestAdapter); 68 DISALLOW_COPY_AND_ASSIGN(TestAdapter);
64 }; 69 };
65 70
66 void TestAdapter::Disable() { 71 void TestAdapter::Disable() {
67 disabled_ = true; 72 disabled_ = true;
68 } 73 }
69 74
75 void TestAdapter::FailStart() {
76 fail_start_ = true;
77 }
78
70 void TestAdapter::Configure(content::WebContents* web_contents, 79 void TestAdapter::Configure(content::WebContents* web_contents,
71 prerender::FinalStatus final_status) { 80 prerender::FinalStatus final_status) {
72 web_contents_ = web_contents; 81 web_contents_ = web_contents;
73 final_status_ = final_status; 82 final_status_ = final_status;
74 } 83 }
75 84
76 bool TestAdapter::CanPrerender() const { 85 bool TestAdapter::CanPrerender() const {
77 return !disabled_; 86 return !disabled_;
78 } 87 }
79 88
80 bool TestAdapter::StartPrerender( 89 bool TestAdapter::StartPrerender(
81 content::BrowserContext* browser_context, 90 content::BrowserContext* browser_context,
82 const GURL& url, 91 const GURL& url,
83 content::SessionStorageNamespace* session_storage_namespace, 92 content::SessionStorageNamespace* session_storage_namespace,
84 const gfx::Size& size) { 93 const gfx::Size& size) {
94 if (fail_start_)
95 return false;
85 active_ = true; 96 active_ = true;
86 return true; 97 return true;
87 } 98 }
88 99
89 content::WebContents* TestAdapter::GetWebContents() const { 100 content::WebContents* TestAdapter::GetWebContents() const {
90 return web_contents_; 101 return web_contents_;
91 } 102 }
92 103
93 prerender::FinalStatus TestAdapter::GetFinalStatus() const { 104 prerender::FinalStatus TestAdapter::GetFinalStatus() const {
94 return final_status_; 105 return final_status_;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 TEST_F(PrerenderingLoaderTest, LoadPageNotAcceptedWhenPrerenderingDisabled) { 324 TEST_F(PrerenderingLoaderTest, LoadPageNotAcceptedWhenPrerenderingDisabled) {
314 test_adapter()->Disable(); 325 test_adapter()->Disable();
315 GURL gurl("http://testit.sea"); 326 GURL gurl("http://testit.sea");
316 EXPECT_TRUE(loader()->IsIdle()); 327 EXPECT_TRUE(loader()->IsIdle());
317 EXPECT_FALSE(loader()->LoadPage( 328 EXPECT_FALSE(loader()->LoadPage(
318 gurl, 329 gurl,
319 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 330 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
320 EXPECT_TRUE(loader()->IsIdle()); 331 EXPECT_TRUE(loader()->IsIdle());
321 } 332 }
322 333
334 TEST_F(PrerenderingLoaderTest, LoadPageNotAcceptedWhenStartPrerenderFalse) {
335 test_adapter()->FailStart();
336 GURL gurl("http://testit.sea");
337 EXPECT_TRUE(loader()->IsIdle());
338 EXPECT_FALSE(loader()->LoadPage(
339 gurl,
340 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
341 EXPECT_TRUE(loader()->IsIdle());
342 }
343
323 } // namespace offline_pages 344 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/prerendering_loader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698