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

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

Issue 2419913002: Fix some WebContents leaks in prerendering tests (Closed)
Patch Set: Created 4 years, 2 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/prerender_adapter_unittest.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/browser/web_contents.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "content/public/test/web_contents_tester.h" 15 #include "content/public/test/web_contents_tester.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace offline_pages { 18 namespace offline_pages {
18 19
19 namespace { 20 namespace {
20 21
21 // Adapter that intercepts prerender stack calls for testing. 22 // Adapter that intercepts prerender stack calls for testing.
22 class TestAdapter : public PrerenderAdapter { 23 class TestAdapter : public PrerenderAdapter {
23 public: 24 public:
24 explicit TestAdapter(PrerenderAdapter::Observer* observer) 25 explicit TestAdapter(PrerenderAdapter::Observer* observer)
25 : PrerenderAdapter(observer), 26 : PrerenderAdapter(observer),
26 active_(false), 27 active_(false),
27 disabled_(false), 28 disabled_(false),
28 fail_start_(false), 29 fail_start_(false),
29 observer_(observer), 30 observer_(observer),
30 web_contents_(nullptr),
31 final_status_(prerender::FINAL_STATUS_MAX) {} 31 final_status_(prerender::FINAL_STATUS_MAX) {}
32 ~TestAdapter() override {} 32 ~TestAdapter() override {}
33 33
34 // PrerenderAdapter implementation. 34 // PrerenderAdapter implementation.
35 bool CanPrerender() const override; 35 bool CanPrerender() const override;
36 bool StartPrerender( 36 bool StartPrerender(
37 content::BrowserContext* browser_context, 37 content::BrowserContext* browser_context,
38 const GURL& url, 38 const GURL& url,
39 content::SessionStorageNamespace* session_storage_namespace, 39 content::SessionStorageNamespace* session_storage_namespace,
40 const gfx::Size& size) override; 40 const gfx::Size& size) override;
(...skipping 14 matching lines...) Expand all
55 prerender::FinalStatus final_status); 55 prerender::FinalStatus final_status);
56 56
57 // Returns the observer for test access. 57 // Returns the observer for test access.
58 PrerenderAdapter::Observer* GetObserver() const { return observer_; } 58 PrerenderAdapter::Observer* GetObserver() const { return observer_; }
59 59
60 private: 60 private:
61 bool active_; 61 bool active_;
62 bool disabled_; 62 bool disabled_;
63 bool fail_start_; 63 bool fail_start_;
64 PrerenderAdapter::Observer* observer_; 64 PrerenderAdapter::Observer* observer_;
65 content::WebContents* web_contents_; 65 std::unique_ptr<content::WebContents> web_contents_;
66 prerender::FinalStatus final_status_; 66 prerender::FinalStatus final_status_;
67 67
68 DISALLOW_COPY_AND_ASSIGN(TestAdapter); 68 DISALLOW_COPY_AND_ASSIGN(TestAdapter);
69 }; 69 };
70 70
71 void TestAdapter::Disable() { 71 void TestAdapter::Disable() {
72 disabled_ = true; 72 disabled_ = true;
73 } 73 }
74 74
75 void TestAdapter::FailStart() { 75 void TestAdapter::FailStart() {
76 fail_start_ = true; 76 fail_start_ = true;
77 } 77 }
78 78
79 void TestAdapter::Configure(content::WebContents* web_contents, 79 void TestAdapter::Configure(content::WebContents* web_contents,
80 prerender::FinalStatus final_status) { 80 prerender::FinalStatus final_status) {
81 web_contents_ = web_contents; 81 web_contents_ = base::WrapUnique(web_contents);
82 final_status_ = final_status; 82 final_status_ = final_status;
83 } 83 }
84 84
85 bool TestAdapter::CanPrerender() const { 85 bool TestAdapter::CanPrerender() const {
86 return !disabled_; 86 return !disabled_;
87 } 87 }
88 88
89 bool TestAdapter::StartPrerender( 89 bool TestAdapter::StartPrerender(
90 content::BrowserContext* browser_context, 90 content::BrowserContext* browser_context,
91 const GURL& url, 91 const GURL& url,
92 content::SessionStorageNamespace* session_storage_namespace, 92 content::SessionStorageNamespace* session_storage_namespace,
93 const gfx::Size& size) { 93 const gfx::Size& size) {
94 if (fail_start_) 94 if (fail_start_)
95 return false; 95 return false;
96 active_ = true; 96 active_ = true;
97 return true; 97 return true;
98 } 98 }
99 99
100 content::WebContents* TestAdapter::GetWebContents() const { 100 content::WebContents* TestAdapter::GetWebContents() const {
101 return web_contents_; 101 return web_contents_.get();
102 } 102 }
103 103
104 prerender::FinalStatus TestAdapter::GetFinalStatus() const { 104 prerender::FinalStatus TestAdapter::GetFinalStatus() const {
105 return final_status_; 105 return final_status_;
106 } 106 }
107 107
108 bool TestAdapter::IsActive() const { 108 bool TestAdapter::IsActive() const {
109 return active_; 109 return active_;
110 } 110 }
111 111
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 test_adapter()->FailStart(); 381 test_adapter()->FailStart();
382 GURL gurl("http://testit.sea"); 382 GURL gurl("http://testit.sea");
383 EXPECT_TRUE(loader()->IsIdle()); 383 EXPECT_TRUE(loader()->IsIdle());
384 EXPECT_FALSE(loader()->LoadPage( 384 EXPECT_FALSE(loader()->LoadPage(
385 gurl, 385 gurl,
386 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 386 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
387 EXPECT_TRUE(loader()->IsIdle()); 387 EXPECT_TRUE(loader()->IsIdle());
388 } 388 }
389 389
390 } // namespace offline_pages 390 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/prerender_adapter_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698