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

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

Issue 1248643004: Test distillability without JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@early
Patch Set: update model, functionally correct locally Created 5 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string.h>
6
7 #include "base/command_line.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "components/dom_distiller/content/browser/distillable_page_utils.h"
14 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h"
15 #include "components/dom_distiller/core/distillable_page_detector.h"
16 #include "components/dom_distiller/core/dom_distiller_switches.h"
17 #include "components/dom_distiller/core/page_features.h"
18 #include "content/public/browser/render_frame_host.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_contents_observer.h"
21 #include "content/public/common/isolated_world_ids.h"
22 #include "content/public/test/browser_test_utils.h"
23 #include "content/public/test/content_browser_test.h"
24 #include "content/public/test/test_utils.h"
25 #include "net/test/embedded_test_server/embedded_test_server.h"
26 #include "testing/gmock/include/gmock/gmock.h"
27
28 namespace dom_distiller {
29
30 using ::testing::_;
31 using namespace switches::reader_mode_heuristics;
32
33 namespace {
34
35 const char* kSimpleArticlePath = "/dom_distiller/simple_article.html";
36 const char* kArticlePath = "/dom_distiller/og_article.html";
37 const char* kNonArticlePath = "/dom_distiller/non_og_article.html";
38
39 class Holder {
40 public:
41 virtual ~Holder() {};
42 virtual void OnResult(bool, bool) = 0;
43 };
44
45 class MockCallback : public Holder {
46 public:
47 MOCK_METHOD2(OnResult, void(bool, bool));
48
49 base::Callback<void(bool, bool)> GetCallback() {
50 return base::Bind(&MockCallback::OnResult, base::Unretained(this));
51 }
52 };
53
54 } // namespace
55
56 template<const char Option[]>
57 class DistillablePageUtilsBrowserTestOption : public InProcessBrowserTest {
58 public:
59 void SetUpCommandLine(base::CommandLine* command_line) override {
60 command_line->AppendSwitch(switches::kEnableDomDistiller);
61 command_line->AppendSwitchASCII(switches::kReaderModeHeuristics,
62 Option);
63 }
64
65 void SetUpOnMainThread() override {
66 InProcessBrowserTest::SetUpOnMainThread();
67 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
68 web_contents_ =
69 browser()->tab_strip_model()->GetActiveWebContents();
70 setCallback(web_contents_, holder_.GetCallback());
71 }
72
73 void NavigateAndWait(const char* url) {
74 const GURL& article_url = embedded_test_server()->GetURL(url);
75
76 // This blocks until the navigation has completely finished.
77 ui_test_utils::NavigateToURL(browser(), article_url);
78 content::WaitForLoadStop(web_contents_);
79 }
80
81 MockCallback holder_;
82 content::WebContents* web_contents_;
83 };
84
85
86 typedef DistillablePageUtilsBrowserTestOption<kAlwaysTrue>
87 DistillablePageUtilsBrowserTestAlways;
88
89 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAlways,
90 TestCallback) {
91 // Run twice to make sure the callback object is still alive.
92 for (unsigned i = 0; i < 2; i++) {
93 testing::InSequence dummy;
94 EXPECT_CALL(holder_, OnResult(true, true)).Times(1);
95 NavigateAndWait(kSimpleArticlePath);
96 }
97 }
98
99
100 typedef DistillablePageUtilsBrowserTestOption<kNone>
101 DistillablePageUtilsBrowserTestNone;
102
103 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestNone,
104 TestCallback) {
105 EXPECT_CALL(holder_, OnResult(_, _)).Times(0);
106 NavigateAndWait(kSimpleArticlePath);
107 }
108
109
110 typedef DistillablePageUtilsBrowserTestOption<kOGArticle>
111 DistillablePageUtilsBrowserTestOG;
112
113 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestOG,
114 TestCallback) {
115 {
116 testing::InSequence dummy;
117 EXPECT_CALL(holder_, OnResult(true, true)).Times(1);
118 NavigateAndWait(kArticlePath);
119 }
120 {
121 testing::InSequence dummy;
122 EXPECT_CALL(holder_, OnResult(false, true)).Times(1);
123 NavigateAndWait(kNonArticlePath);
124 }
125 }
126
127
128 typedef DistillablePageUtilsBrowserTestOption<kAdaBoost>
129 DistillablePageUtilsBrowserTestAdaboost;
130
131 IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAdaboost,
132 TestCallback) {
133 {
134 testing::InSequence dummy;
135 EXPECT_CALL(holder_, OnResult(true, false)).Times(1);
136 EXPECT_CALL(holder_, OnResult(true, true)).Times(1);
137 NavigateAndWait(kSimpleArticlePath);
138 }
139 {
140 testing::InSequence dummy;
141 EXPECT_CALL(holder_, OnResult(false, false)).Times(1);
142 EXPECT_CALL(holder_, OnResult(false, true)).Times(1);
143 NavigateAndWait(kNonArticlePath);
144 }
145 }
146
147 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698