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

Side by Side Diff: chrome/browser/dom_distiller/distillable_page_utils_browsertest.cc

Issue 2171813003: Fix timeout of DistillablePageUtilsBrowserTest on DrMemory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <string.h> 5 #include <string.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 class MockDelegate : public Holder { 47 class MockDelegate : public Holder {
48 public: 48 public:
49 MOCK_METHOD2(OnResult, void(bool, bool)); 49 MOCK_METHOD2(OnResult, void(bool, bool));
50 50
51 base::Callback<void(bool, bool)> GetDelegate() { 51 base::Callback<void(bool, bool)> GetDelegate() {
52 return base::Bind(&MockDelegate::OnResult, base::Unretained(this)); 52 return base::Bind(&MockDelegate::OnResult, base::Unretained(this));
53 } 53 }
54 }; 54 };
55 55
56 // Wait a bit to make sure there are no extra calls after the last expected
57 // call. All the expected calls happen within ~1ms on linux release build,
58 // so 100ms should be pretty safe to catch extra calls.
59 // If there are no extra calls, changing this doesn't change the test result.
60 const unsigned kWaitAfterLastCall = 100;
Lei Zhang 2016/07/21 22:54:26 s/unsigned/int/ ? As it's being used in quitAfter(
wychen 2016/07/22 22:39:53 Converted all to unsigned. Added Ms.
Lei Zhang 2016/07/26 20:56:35 Any reason to favor unsigned? TimeDelta::FromMilli
wychen 2016/07/27 01:41:12 Done
61
62 // If there are no expected calls, we wait for a while to make sure there are
Lei Zhang 2016/07/21 22:54:26 s/we/the test/ Sometimes "we" can be unclear as t
wychen 2016/07/22 22:39:53 Done.
63 // no calls in this period of time. When there are expected calls, they happen
64 // within 100ms after content::WaitForLoadStop() on linux release build, and
65 // 10X safety margin is used.
66 // If there are no extra calls, changing this doesn't change the test result.
67 const unsigned kWaitNoExpectedCall = 1000;
68
69 // QuitWhenIdleClosure() would become nop if it is called before
Lei Zhang 2016/07/21 22:54:26 s/nop/no-op/
wychen 2016/07/22 22:39:53 Done.
70 // content::RunMessageLoop(). This timeout should be long enough to make sure
71 // at least one QuitWhenIdleClosure() is called after RunMessageLoop().
72 // All tests are limited by kWaitAfterLastCall or kWaitNoExpectedCall, so
Lei Zhang 2016/07/21 22:54:26 Refer to variables as |variable_name|
wychen 2016/07/22 22:39:53 Done.
73 // making this longer doesn't actually make tests run for longer, unless
74 // kWaitAfterLastCall or kWaitNoExpectedCall are so small or the test is so
75 // slow, for example, on Dr. Memory or Android, that QuitWhenIdleClosure()
76 // is called prematurely. 100X safety margin is used.
77 const unsigned kDefaultTimeout = 10000;
78
79 void quitAfter(int time_ms) {
Lei Zhang 2016/07/21 22:54:26 C++ methods have CapitalNames(). Have you been wri
wychen 2016/07/22 22:39:53 Oops.
80 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
81 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
82 base::TimeDelta::FromMilliseconds(time_ms));
83 }
84
85 void quitSoon() {
86 quitAfter(kWaitAfterLastCall);
87 }
88
56 } // namespace 89 } // namespace
57 90
58 template<const char Option[]> 91 template<const char Option[]>
59 class DistillablePageUtilsBrowserTestOption : public InProcessBrowserTest { 92 class DistillablePageUtilsBrowserTestOption : public InProcessBrowserTest {
60 public: 93 public:
61 void SetUpCommandLine(base::CommandLine* command_line) override { 94 void SetUpCommandLine(base::CommandLine* command_line) override {
62 command_line->AppendSwitch(switches::kEnableDomDistiller); 95 command_line->AppendSwitch(switches::kEnableDomDistiller);
63 command_line->AppendSwitchASCII(switches::kReaderModeHeuristics, 96 command_line->AppendSwitchASCII(switches::kReaderModeHeuristics,
64 Option); 97 Option);
65 } 98 }
66 99
67 void SetUpOnMainThread() override { 100 void SetUpOnMainThread() override {
68 InProcessBrowserTest::SetUpOnMainThread(); 101 InProcessBrowserTest::SetUpOnMainThread();
69 ASSERT_TRUE(embedded_test_server()->Start()); 102 ASSERT_TRUE(embedded_test_server()->Start());
70 web_contents_ = 103 web_contents_ =
71 browser()->tab_strip_model()->GetActiveWebContents(); 104 browser()->tab_strip_model()->GetActiveWebContents();
72 setDelegate(web_contents_, holder_.GetDelegate()); 105 setDelegate(web_contents_, holder_.GetDelegate());
73 } 106 }
74 107
75 void NavigateAndWait(const char* url) { 108 void NavigateAndWait(const char* url, unsigned timeout_ms = 0) {
Lei Zhang 2016/07/21 22:54:26 int here as well.
Lei Zhang 2016/07/21 22:54:26 There aren't that many callers. Just fix the calls
wychen 2016/07/22 22:39:53 This is one extra timeout. When not passed, it's n
wychen 2016/07/22 22:39:53 Done.
Lei Zhang 2016/07/23 00:51:24 I still stand by my original statement since there
wychen 2016/07/24 23:50:31 Make sense. Removed the default parameter.
76 GURL article_url(url); 109 GURL article_url(url);
77 if (base::StartsWith(url, "/", base::CompareCase::SENSITIVE)) { 110 if (base::StartsWith(url, "/", base::CompareCase::SENSITIVE)) {
78 article_url = embedded_test_server()->GetURL(url); 111 article_url = embedded_test_server()->GetURL(url);
79 } 112 }
80 113
81 // This blocks until the navigation has completely finished. 114 // This blocks until the navigation has completely finished.
82 ui_test_utils::NavigateToURL(browser(), article_url); 115 ui_test_utils::NavigateToURL(browser(), article_url);
83 content::WaitForLoadStop(web_contents_); 116 content::WaitForLoadStop(web_contents_);
84 117
85 // Wait a bit for the message. 118 quitAfter(kDefaultTimeout);
86 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 119 if (timeout_ms) {
87 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 120 // Local time-out for the tests that don't expect callbacks.
88 base::TimeDelta::FromMilliseconds(100)); 121 quitAfter(timeout_ms);
122 }
89 content::RunMessageLoop(); 123 content::RunMessageLoop();
90 } 124 }
91 125
92 MockDelegate holder_; 126 MockDelegate holder_;
93 content::WebContents* web_contents_; 127 content::WebContents* web_contents_;
94 }; 128 };
95 129
96 130
97 using DistillablePageUtilsBrowserTestAlways = 131 using DistillablePageUtilsBrowserTestAlways =
98 DistillablePageUtilsBrowserTestOption<kAlwaysTrue>; 132 DistillablePageUtilsBrowserTestOption<kAlwaysTrue>;
99 133
100 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAlways, 134 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAlways,
101 TestDelegate) { 135 TestDelegate) {
102 // Run twice to make sure the delegate object is still alive.
103 for (int i = 0; i < 2; ++i) {
104 testing::InSequence dummy;
105 EXPECT_CALL(holder_, OnResult(true, true)).Times(1);
106 NavigateAndWait(kSimpleArticlePath);
107 }
108 for (unsigned i = 0; i < sizeof(kAllPaths) / sizeof(kAllPaths[0]); ++i) { 136 for (unsigned i = 0; i < sizeof(kAllPaths) / sizeof(kAllPaths[0]); ++i) {
109 testing::InSequence dummy; 137 testing::InSequence dummy;
110 EXPECT_CALL(holder_, OnResult(true, true)).Times(1); 138 EXPECT_CALL(holder_, OnResult(true, true))
139 .WillOnce(testing::InvokeWithoutArgs(quitSoon));
111 NavigateAndWait(kAllPaths[i]); 140 NavigateAndWait(kAllPaths[i]);
112 } 141 }
113 // Test pages that we don't care about its distillability. 142 // Test pages that we don't care about its distillability.
114 { 143 {
115 testing::InSequence dummy; 144 testing::InSequence dummy;
116 EXPECT_CALL(holder_, OnResult(_, _)).Times(0); 145 EXPECT_CALL(holder_, OnResult(_, _)).Times(0);
117 NavigateAndWait("about:blank"); 146 NavigateAndWait("about:blank", kWaitNoExpectedCall);
118 } 147 }
119 } 148 }
120 149
121 150
122 using DistillablePageUtilsBrowserTestNone = 151 using DistillablePageUtilsBrowserTestNone =
123 DistillablePageUtilsBrowserTestOption<kNone>; 152 DistillablePageUtilsBrowserTestOption<kNone>;
124 153
125 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestNone, 154 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestNone,
126 TestDelegate) { 155 TestDelegate) {
127 EXPECT_CALL(holder_, OnResult(_, _)).Times(0); 156 EXPECT_CALL(holder_, OnResult(_, _)).Times(0);
128 NavigateAndWait(kSimpleArticlePath); 157 NavigateAndWait(kSimpleArticlePath, kWaitNoExpectedCall);
129 } 158 }
130 159
131 160
132 using DistillablePageUtilsBrowserTestOG = 161 using DistillablePageUtilsBrowserTestOG =
133 DistillablePageUtilsBrowserTestOption<kOGArticle>; 162 DistillablePageUtilsBrowserTestOption<kOGArticle>;
134 163
135 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestOG, 164 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestOG,
136 TestDelegate) { 165 TestDelegate) {
137 { 166 {
138 testing::InSequence dummy; 167 testing::InSequence dummy;
139 EXPECT_CALL(holder_, OnResult(true, true)).Times(1); 168 EXPECT_CALL(holder_, OnResult(true, true))
169 .WillOnce(testing::InvokeWithoutArgs(quitSoon));
140 NavigateAndWait(kArticlePath); 170 NavigateAndWait(kArticlePath);
141 } 171 }
142 { 172 {
143 testing::InSequence dummy; 173 testing::InSequence dummy;
144 EXPECT_CALL(holder_, OnResult(false, true)).Times(1); 174 EXPECT_CALL(holder_, OnResult(false, true))
175 .WillOnce(testing::InvokeWithoutArgs(quitSoon));
145 NavigateAndWait(kNonArticlePath); 176 NavigateAndWait(kNonArticlePath);
146 } 177 }
147 } 178 }
148 179
149 180
150 using DistillablePageUtilsBrowserTestAdaboost = 181 using DistillablePageUtilsBrowserTestAdaboost =
151 DistillablePageUtilsBrowserTestOption<kAdaBoost>; 182 DistillablePageUtilsBrowserTestOption<kAdaBoost>;
152 183
153 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAdaboost, 184 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAdaboost,
154 TestDelegate) { 185 TestDelegate) {
155 const char* paths[] = {kSimpleArticlePath, kSimpleArticleIFramePath}; 186 const char* paths[] = {kSimpleArticlePath, kSimpleArticleIFramePath};
156 for (unsigned i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) { 187 for (unsigned i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) {
157 testing::InSequence dummy; 188 testing::InSequence dummy;
158 EXPECT_CALL(holder_, OnResult(true, false)).Times(1); 189 EXPECT_CALL(holder_, OnResult(true, false)).Times(1);
159 EXPECT_CALL(holder_, OnResult(true, true)).Times(1); 190 EXPECT_CALL(holder_, OnResult(true, true))
191 .WillOnce(testing::InvokeWithoutArgs(quitSoon));
160 NavigateAndWait(paths[i]); 192 NavigateAndWait(paths[i]);
161 } 193 }
162 { 194 {
163 testing::InSequence dummy; 195 testing::InSequence dummy;
164 EXPECT_CALL(holder_, OnResult(false, false)).Times(1); 196 EXPECT_CALL(holder_, OnResult(false, false)).Times(1);
165 EXPECT_CALL(holder_, OnResult(false, true)).Times(1); 197 EXPECT_CALL(holder_, OnResult(false, true))
198 .WillOnce(testing::InvokeWithoutArgs(quitSoon));
166 NavigateAndWait(kNonArticlePath); 199 NavigateAndWait(kNonArticlePath);
167 } 200 }
168 } 201 }
169 202
170 } // namespace dom_distiller 203 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698