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

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: move tests, remove dbg msg Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/tab_helpers.cc » ('j') | chrome/browser/ui/tab_helpers.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a4913ddfd26926bbd02daf4ddfe8260145232e89
--- /dev/null
+++ b/chrome/browser/dom_distiller/distillable_page_utils_browsertest.cc
@@ -0,0 +1,112 @@
+// 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 "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.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/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"
+
+namespace dom_distiller {
+
+namespace {
+
+const char* kSimpleArticlePath = "/dom_distiller/simple_article.html";
+
+class ResultHolder {
+ public:
+ ResultHolder(base::Closure callback) : callback_(callback) {}
+
+ void OnResult(bool result) {
+ result_ = result;
+ callback_.Run();
+ }
+
+ bool GetResult() {
+ return result_;
+ }
+
+ base::Callback<void(bool)> GetCallback() {
+ return base::Bind(&ResultHolder::OnResult, base::Unretained(this));
+ }
+
+ private:
+ base::Closure callback_;
+ bool result_;
+};
+
+} // namespace
+
+class DistillablePageUtilsBrowserTest : public InProcessBrowserTest {
+ public:
+ void SetUpOnMainThread() override {
+ if (!DistillerJavaScriptWorldIdIsSet()) {
+ SetDistillerJavaScriptWorldId(content::ISOLATED_WORLD_ID_CONTENT_END);
+ }
+ InProcessBrowserTest::SetUpOnMainThread();
+ }
+
+ void assertDistillability(bool);
+};
+
+void DistillablePageUtilsBrowserTest::assertDistillability(bool distillable)
+{
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ const GURL& article_url = embedded_test_server()->GetURL(kSimpleArticlePath);
+
+ // This blocks until the navigation has completely finished.
+ ui_test_utils::NavigateToURL(browser(), article_url);
+ content::WaitForLoadStop(web_contents);
+
+ // Set up AdaBoost.
+ scoped_ptr<AdaBoostProto> proto(new AdaBoostProto);
+ proto->set_num_features(kDerivedFeaturesCount);
+ proto->set_num_stumps(1);
+
+ StumpProto* stump = proto->add_stump();
+ stump->set_feature_number(0);
+ int weight = distillable ? 1 : -1;
+ stump->set_weight(weight);
+ stump->set_split(-1);
+ scoped_ptr<DistillablePageDetector> detector(
+ new DistillablePageDetector(proto.Pass()));
+ EXPECT_DOUBLE_EQ(0.5 * weight, detector->GetThreshold());
+ // The first value of the first feature is either 0 or 1. Since the stump's
+ // split is -1, the stump weight will be applied to any set of derived
+ // features.
+ base::RunLoop run_loop_;
+ ResultHolder holder(run_loop_.QuitClosure());
+ IsDistillablePageForDetector(web_contents, detector.get(),
+ holder.GetCallback());
+ run_loop_.Run();
+ ASSERT_TRUE(holder.GetResult() == distillable);
+}
+
+IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTest,
+ TestIsDistillablePage) {
+ assertDistillability(true);
+}
+
+IN_PROC_BROWSER_TEST_F(DistillablePageUtilsBrowserTest,
+ TestIsNotDistillablePage) {
+ assertDistillability(false);
+}
+
+} // namespace dom_distiller
« no previous file with comments | « no previous file | chrome/browser/ui/tab_helpers.cc » ('j') | chrome/browser/ui/tab_helpers.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698