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

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: use signed time Created 4 years, 4 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 | tools/valgrind/gtest_exclude/browser_tests.gtest-drmemory.txt » ('j') | 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 int kWaitAfterLastCallMs = 100;
61
62 // If there are no expected calls, the test wait for a while to make sure there
63 // are // no calls in this period of time. When there are expected calls, they
64 // happen within 100ms after content::WaitForLoadStop() on linux release build,
65 // and 10X safety margin is used.
66 // If there are no extra calls, changing this doesn't change the test result.
67 const int kWaitNoExpectedCallMs = 1000;
68
69 // QuitWhenIdleClosure() would become no-op if it is called before
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
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 int kDefaultTimeoutMs = 10000;
78
79 void QuitAfter(int time_ms) {
80 DCHECK_GE(time_ms, 0);
81 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
82 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
83 base::TimeDelta::FromMilliseconds(time_ms));
84 }
85
86 void QuitSoon() {
87 QuitAfter(kWaitAfterLastCallMs);
88 }
89
56 } // namespace 90 } // namespace
57 91
58 template<const char Option[]> 92 template<const char Option[]>
59 class DistillablePageUtilsBrowserTestOption : public InProcessBrowserTest { 93 class DistillablePageUtilsBrowserTestOption : public InProcessBrowserTest {
60 public: 94 public:
61 void SetUpCommandLine(base::CommandLine* command_line) override { 95 void SetUpCommandLine(base::CommandLine* command_line) override {
62 command_line->AppendSwitch(switches::kEnableDomDistiller); 96 command_line->AppendSwitch(switches::kEnableDomDistiller);
63 command_line->AppendSwitchASCII(switches::kReaderModeHeuristics, 97 command_line->AppendSwitchASCII(switches::kReaderModeHeuristics,
64 Option); 98 Option);
65 } 99 }
66 100
67 void SetUpOnMainThread() override { 101 void SetUpOnMainThread() override {
68 InProcessBrowserTest::SetUpOnMainThread(); 102 InProcessBrowserTest::SetUpOnMainThread();
69 ASSERT_TRUE(embedded_test_server()->Start()); 103 ASSERT_TRUE(embedded_test_server()->Start());
70 web_contents_ = 104 web_contents_ =
71 browser()->tab_strip_model()->GetActiveWebContents(); 105 browser()->tab_strip_model()->GetActiveWebContents();
72 setDelegate(web_contents_, holder_.GetDelegate()); 106 setDelegate(web_contents_, holder_.GetDelegate());
73 } 107 }
74 108
75 void NavigateAndWait(const char* url) { 109 void NavigateAndWait(const char* url, int timeout_ms) {
76 GURL article_url(url); 110 GURL article_url(url);
77 if (base::StartsWith(url, "/", base::CompareCase::SENSITIVE)) { 111 if (base::StartsWith(url, "/", base::CompareCase::SENSITIVE)) {
78 article_url = embedded_test_server()->GetURL(url); 112 article_url = embedded_test_server()->GetURL(url);
79 } 113 }
80 114
81 // This blocks until the navigation has completely finished. 115 // This blocks until the navigation has completely finished.
82 ui_test_utils::NavigateToURL(browser(), article_url); 116 ui_test_utils::NavigateToURL(browser(), article_url);
83 content::WaitForLoadStop(web_contents_); 117 content::WaitForLoadStop(web_contents_);
84 118
85 // Wait a bit for the message. 119 QuitAfter(kDefaultTimeoutMs);
86 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 120 if (timeout_ms) {
87 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 121 // Local time-out for the tests that don't expect callbacks.
88 base::TimeDelta::FromMilliseconds(100)); 122 QuitAfter(timeout_ms);
123 }
89 content::RunMessageLoop(); 124 content::RunMessageLoop();
90 } 125 }
91 126
92 MockDelegate holder_; 127 MockDelegate holder_;
93 content::WebContents* web_contents_; 128 content::WebContents* web_contents_;
94 }; 129 };
95 130
96 131
97 using DistillablePageUtilsBrowserTestAlways = 132 using DistillablePageUtilsBrowserTestAlways =
98 DistillablePageUtilsBrowserTestOption<kAlwaysTrue>; 133 DistillablePageUtilsBrowserTestOption<kAlwaysTrue>;
99 134
100 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAlways, 135 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAlways,
101 TestDelegate) { 136 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) { 137 for (unsigned i = 0; i < sizeof(kAllPaths) / sizeof(kAllPaths[0]); ++i) {
109 testing::InSequence dummy; 138 testing::InSequence dummy;
110 EXPECT_CALL(holder_, OnResult(true, true)).Times(1); 139 EXPECT_CALL(holder_, OnResult(true, true))
111 NavigateAndWait(kAllPaths[i]); 140 .WillOnce(testing::InvokeWithoutArgs(QuitSoon));
141 NavigateAndWait(kAllPaths[i], 0);
112 } 142 }
113 // Test pages that we don't care about its distillability. 143 // Test pages that we don't care about its distillability.
114 { 144 {
115 testing::InSequence dummy; 145 testing::InSequence dummy;
116 EXPECT_CALL(holder_, OnResult(_, _)).Times(0); 146 EXPECT_CALL(holder_, OnResult(_, _)).Times(0);
117 NavigateAndWait("about:blank"); 147 NavigateAndWait("about:blank", kWaitNoExpectedCallMs);
118 } 148 }
119 } 149 }
120 150
121 151
122 using DistillablePageUtilsBrowserTestNone = 152 using DistillablePageUtilsBrowserTestNone =
123 DistillablePageUtilsBrowserTestOption<kNone>; 153 DistillablePageUtilsBrowserTestOption<kNone>;
124 154
125 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestNone, 155 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestNone,
126 TestDelegate) { 156 TestDelegate) {
127 EXPECT_CALL(holder_, OnResult(_, _)).Times(0); 157 EXPECT_CALL(holder_, OnResult(_, _)).Times(0);
128 NavigateAndWait(kSimpleArticlePath); 158 NavigateAndWait(kSimpleArticlePath, kWaitNoExpectedCallMs);
129 } 159 }
130 160
131 161
132 using DistillablePageUtilsBrowserTestOG = 162 using DistillablePageUtilsBrowserTestOG =
133 DistillablePageUtilsBrowserTestOption<kOGArticle>; 163 DistillablePageUtilsBrowserTestOption<kOGArticle>;
134 164
135 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestOG, 165 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestOG,
136 TestDelegate) { 166 TestDelegate) {
137 { 167 {
138 testing::InSequence dummy; 168 testing::InSequence dummy;
139 EXPECT_CALL(holder_, OnResult(true, true)).Times(1); 169 EXPECT_CALL(holder_, OnResult(true, true))
140 NavigateAndWait(kArticlePath); 170 .WillOnce(testing::InvokeWithoutArgs(QuitSoon));
171 NavigateAndWait(kArticlePath, 0);
141 } 172 }
142 { 173 {
143 testing::InSequence dummy; 174 testing::InSequence dummy;
144 EXPECT_CALL(holder_, OnResult(false, true)).Times(1); 175 EXPECT_CALL(holder_, OnResult(false, true))
145 NavigateAndWait(kNonArticlePath); 176 .WillOnce(testing::InvokeWithoutArgs(QuitSoon));
177 NavigateAndWait(kNonArticlePath, 0);
146 } 178 }
147 } 179 }
148 180
149 181
150 using DistillablePageUtilsBrowserTestAdaboost = 182 using DistillablePageUtilsBrowserTestAdaboost =
151 DistillablePageUtilsBrowserTestOption<kAdaBoost>; 183 DistillablePageUtilsBrowserTestOption<kAdaBoost>;
152 184
153 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAdaboost, 185 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAdaboost,
154 TestDelegate) { 186 TestDelegate) {
155 const char* paths[] = {kSimpleArticlePath, kSimpleArticleIFramePath}; 187 const char* paths[] = {kSimpleArticlePath, kSimpleArticleIFramePath};
156 for (unsigned i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) { 188 for (unsigned i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) {
157 testing::InSequence dummy; 189 testing::InSequence dummy;
158 EXPECT_CALL(holder_, OnResult(true, false)).Times(1); 190 EXPECT_CALL(holder_, OnResult(true, false)).Times(1);
159 EXPECT_CALL(holder_, OnResult(true, true)).Times(1); 191 EXPECT_CALL(holder_, OnResult(true, true))
160 NavigateAndWait(paths[i]); 192 .WillOnce(testing::InvokeWithoutArgs(QuitSoon));
193 NavigateAndWait(paths[i], 0);
161 } 194 }
162 { 195 {
163 testing::InSequence dummy; 196 testing::InSequence dummy;
164 EXPECT_CALL(holder_, OnResult(false, false)).Times(1); 197 EXPECT_CALL(holder_, OnResult(false, false)).Times(1);
165 EXPECT_CALL(holder_, OnResult(false, true)).Times(1); 198 EXPECT_CALL(holder_, OnResult(false, true))
166 NavigateAndWait(kNonArticlePath); 199 .WillOnce(testing::InvokeWithoutArgs(QuitSoon));
200 NavigateAndWait(kNonArticlePath, 0);
167 } 201 }
168 } 202 }
169 203
170 } // namespace dom_distiller 204 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/browser_tests.gtest-drmemory.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698