Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/profiles/profile.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 11 #include "chrome/common/chrome_switches.h" | |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | |
| 14 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" | |
| 15 #include "content/public/browser/render_view_host.h" | |
| 16 #include "content/public/browser/url_data_source.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 18 #include "content/public/browser/web_contents_observer.h" | |
| 19 #include "content/public/common/url_constants.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 | |
| 22 namespace dom_distiller { | |
| 23 | |
| 24 // WebContents observer that stores reference to the current |RenderViewHost|. | |
| 25 class LoadSuccessObserver : public content::WebContentsObserver { | |
| 26 public: | |
| 27 explicit LoadSuccessObserver(content::WebContents* contents) | |
| 28 : content::WebContentsObserver(contents), | |
| 29 validated_url_(GURL()), | |
| 30 finished_load_(false), | |
| 31 load_failed_(false), | |
| 32 render_view_host_(NULL) {} | |
| 33 | |
| 34 virtual void DidFinishLoad(int64 frame_id, | |
| 35 const GURL& validated_url, | |
| 36 bool is_main_frame, | |
| 37 content::RenderViewHost* render_view_host) | |
| 38 OVERRIDE { | |
| 39 validated_url_ = validated_url; | |
| 40 finished_load_ = true; | |
| 41 render_view_host_ = render_view_host; | |
| 42 } | |
| 43 | |
| 44 virtual void DidFailProvisionalLoad(int64 frame_id, | |
| 45 const base::string16& frame_unique_name, | |
| 46 bool is_main_frame, | |
| 47 const GURL& validated_url, | |
| 48 int error_code, | |
| 49 const base::string16& error_description, | |
| 50 content::RenderViewHost* render_view_host) | |
| 51 OVERRIDE { | |
| 52 load_failed_ = true; | |
| 53 } | |
| 54 | |
| 55 const GURL& validated_url() const { return validated_url_; } | |
| 56 const bool finished_load() const { return finished_load_; } | |
| 57 const bool load_failed() const { return load_failed_; } | |
| 58 | |
| 59 const content::RenderViewHost* render_view_host() const { | |
| 60 return render_view_host_; | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 GURL validated_url_; | |
| 65 bool finished_load_; | |
| 66 bool load_failed_; | |
| 67 content::RenderViewHost* render_view_host_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(LoadSuccessObserver); | |
| 70 }; | |
| 71 | |
| 72 class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest { | |
| 73 public: | |
| 74 DomDistillerViewerSourceBrowserTest() {} | |
| 75 virtual ~DomDistillerViewerSourceBrowserTest() {} | |
| 76 | |
| 77 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 78 command_line->AppendSwitch(switches::kEnableDomDistiller); | |
| 79 } | |
| 80 }; | |
| 81 | |
| 82 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings | |
| 83 // are enabled. | |
| 84 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, NoWebUIBindings) { | |
| 85 // Ensure the source is registered. | |
| 86 content::URLDataSource::Add(browser()->profile(), | |
|
nasko
2014/01/23 16:37:04
If you explicitly register the data source, then y
nyquist
2014/01/24 03:03:07
We haven't decided where we want to register the d
| |
| 87 new DomDistillerViewerSource()); | |
| 88 | |
| 89 // Setup observer to inspect the RenderViewHost after committed navigation. | |
| 90 content::WebContents* contents = | |
| 91 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 92 LoadSuccessObserver observer(contents); | |
| 93 | |
| 94 // Navigate to a URL which the source should respond to. | |
| 95 std::string url_without_scheme = "://distilled"; | |
| 96 GURL url(chrome::kDomDistillerScheme + url_without_scheme); | |
| 97 ui_test_utils::NavigateToURL(browser(), url); | |
| 98 | |
| 99 // A navigation should have succeeded to the correct URL. | |
| 100 ASSERT_FALSE(observer.load_failed()); | |
| 101 ASSERT_TRUE(observer.finished_load()); | |
| 102 ASSERT_EQ(url, observer.validated_url()); | |
| 103 // Ensure no bindings. | |
| 104 const content::RenderViewHost* render_view_host = observer.render_view_host(); | |
| 105 ASSERT_EQ(0, render_view_host->GetEnabledBindings()); | |
| 106 } | |
| 107 | |
| 108 } // namespace dom_distiller | |
| OLD | NEW |