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

Unified Diff: chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc

Issue 1231083007: Expose distiller functions to JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-content
Patch Set: Update to use StrongBinding and rebase 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
Index: chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
diff --git a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
index 83ac18e9fe7b8ef2ce1c656445f8eefda5efa634..24637e8e56b0b4dc4b34f93c7f86bf1f68a3e624 100644
--- a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
+++ b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
@@ -12,6 +12,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_isolated_world_ids.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/distiller_javascript_utils.h"
@@ -67,6 +69,10 @@ const char kGetBodyClass[] =
const unsigned kDarkToolbarThemeColor = 0xFF1A1A1A;
+const char kTestDistillerObject[] =
+ "window.domAutomationController.send("
+ "typeof distiller == 'object')";
+
void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) {
(*map)[e.entry_id()] = e;
}
@@ -320,7 +326,66 @@ IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
}
IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
- MultiPageArticle) {
+ DistillerJavaScriptExposed) {
+ // Navigate to a distiller URL.
+ GURL url(std::string(kDomDistillerScheme) + "://url");
+ chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
+ chrome::Navigate(&params);
+
+ content::WebContents* contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+
+ // Wait for the page load to complete (this will be a distiller error page).
+ content::WaitForLoadStop(contents);
+
+ bool result;
+ // Execute in isolated world; where all distiller scripts are run.
+ EXPECT_TRUE(content::ExecuteScriptInIsolatedWorldAndExtractBool(
+ contents, chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL, kTestDistillerObject,
+ &result));
+ EXPECT_TRUE(result);
+}
+
+IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
+ DistillerJavaScriptNotInMainWorld) {
+ // Navigate to a distiller URL.
+ GURL url(std::string(kDomDistillerScheme) + "://url");
+ chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
+ chrome::Navigate(&params);
+
+ content::WebContents* contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+
+ // Wait for the page load to complete (this will be a distiller error page).
+ content::WaitForLoadStop(contents);
+
+ bool result;
+ // Execute in main world, the distiller object should not be here.
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents, kTestDistillerObject, &result));
+ EXPECT_FALSE(result);
+}
+
+IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
+ DistillerJavaScriptNotExposed) {
+ // Navigate to a non-distiller URL.
+ GURL url("http://url");
+ chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
+ chrome::Navigate(&params);
+
+ content::WebContents* contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+
+ // Wait for the page load to complete.
+ content::WaitForLoadStop(contents);
+
+ bool result;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents, kTestDistillerObject, &result));
+ EXPECT_FALSE(result);
+}
+
+IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, MultiPageArticle) {
expect_distillation_ = false;
expect_distiller_page_ = true;
dom_distiller::DomDistillerServiceFactory::GetInstance()

Powered by Google App Engine
This is Rietveld 408576698