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

Unified 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: fix browsertest, merge webkit CL, merge http://crrev.com/1403413004 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/dom_distiller/distillable_page_utils_browsertest.cc
diff --git a/chrome/browser/dom_distiller/distillable_page_utils_browsertest.cc b/chrome/browser/dom_distiller/distillable_page_utils_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..55ce895925db8f0d8161e112a4bd8c00b88a4e63
--- /dev/null
+++ b/chrome/browser/dom_distiller/distillable_page_utils_browsertest.cc
@@ -0,0 +1,154 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string.h>
+
+#include "base/command_line.h"
+#include "base/thread_task_runner_handle.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "components/dom_distiller/content/browser/distillable_page_utils.h"
+#include "components/dom_distiller/content/browser/distiller_javascript_utils.h"
+#include "components/dom_distiller/core/distillable_page_detector.h"
+#include "components/dom_distiller/core/dom_distiller_switches.h"
+#include "components/dom_distiller/core/page_features.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/common/isolated_world_ids.h"
+#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/content_browser_test.h"
+#include "content/public/test/test_utils.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace dom_distiller {
+
+using ::testing::_;
+using namespace switches::reader_mode_heuristics;
+
+namespace {
+
+const char* kSimpleArticlePath = "/dom_distiller/simple_article.html";
+const char* kArticlePath = "/dom_distiller/og_article.html";
+const char* kNonArticlePath = "/dom_distiller/non_og_article.html";
+
+class Holder {
+ public:
+ virtual ~Holder() {};
+ virtual void OnResult(bool, bool) = 0;
+};
+
+class MockCallback : public Holder {
+ public:
+ MOCK_METHOD2(OnResult, void(bool, bool));
+
+ base::Callback<void(bool, bool)> GetCallback() {
+ return base::Bind(&MockCallback::OnResult, base::Unretained(this));
+ }
+};
+
+} // namespace
+
+template<const char Option[]>
+class DistillablePageUtilsBrowserTestOption : public InProcessBrowserTest {
+ public:
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ command_line->AppendSwitch(switches::kEnableDomDistiller);
+ command_line->AppendSwitchASCII(switches::kReaderModeHeuristics,
+ Option);
+ }
+
+ void SetUpOnMainThread() override {
+ InProcessBrowserTest::SetUpOnMainThread();
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+ web_contents_ =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ setCallback(web_contents_, holder_.GetCallback());
+ }
+
+ void NavigateAndWait(const char* url) {
+ const GURL& article_url = embedded_test_server()->GetURL(url);
+
+ // This blocks until the navigation has completely finished.
+ ui_test_utils::NavigateToURL(browser(), article_url);
+ content::WaitForLoadStop(web_contents_);
+
+ // Wait a bit for the message.
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
+ base::TimeDelta::FromMilliseconds(100));
+ content::RunMessageLoop();
+ }
+
+ MockCallback holder_;
+ content::WebContents* web_contents_;
+};
+
+
+typedef DistillablePageUtilsBrowserTestOption<kAlwaysTrue>
+ DistillablePageUtilsBrowserTestAlways;
+
+IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAlways,
+ TestCallback) {
+ // Run twice to make sure the callback object is still alive.
+ for (unsigned i = 0; i < 2; i++) {
+ testing::InSequence dummy;
+ EXPECT_CALL(holder_, OnResult(true, true)).Times(1);
+ NavigateAndWait(kSimpleArticlePath);
+ }
+}
+
+
+typedef DistillablePageUtilsBrowserTestOption<kNone>
+ DistillablePageUtilsBrowserTestNone;
+
+IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestNone,
+ TestCallback) {
+ EXPECT_CALL(holder_, OnResult(_, _)).Times(0);
+ NavigateAndWait(kSimpleArticlePath);
+}
+
+
+typedef DistillablePageUtilsBrowserTestOption<kOGArticle>
+ DistillablePageUtilsBrowserTestOG;
+
+IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestOG,
+ TestCallback) {
+ {
+ testing::InSequence dummy;
+ EXPECT_CALL(holder_, OnResult(true, true)).Times(1);
+ NavigateAndWait(kArticlePath);
+ }
+ {
+ testing::InSequence dummy;
+ EXPECT_CALL(holder_, OnResult(false, true)).Times(1);
+ NavigateAndWait(kNonArticlePath);
+ }
+}
+
+
+typedef DistillablePageUtilsBrowserTestOption<kAdaBoost>
+ DistillablePageUtilsBrowserTestAdaboost;
+
+IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTestAdaboost,
+ TestCallback) {
+ {
+ testing::InSequence dummy;
+ EXPECT_CALL(holder_, OnResult(true, false)).Times(1);
+ EXPECT_CALL(holder_, OnResult(true, true)).Times(1);
+ NavigateAndWait(kSimpleArticlePath);
+ }
+ {
+ testing::InSequence dummy;
+ EXPECT_CALL(holder_, OnResult(false, false)).Times(1);
+ EXPECT_CALL(holder_, OnResult(false, true)).Times(1);
+ NavigateAndWait(kNonArticlePath);
+ }
+}
+
+} // namespace dom_distiller
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/ui/webui/print_preview/print_preview_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698