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

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

Issue 105723002: Add the scheme chrome-distiller:// and hook up data source. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments from jam@ Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
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/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/common/url_constants.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "components/dom_distiller/content/dom_distiller_viewer_source.h"
16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/url_data_source.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_observer.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 bool finished_load() const { return finished_load_; }
57 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 // TODO(nyquist): Remove when the source is always registered on startup.
87 content::URLDataSource::Add(
88 browser()->profile(),
89 new DomDistillerViewerSource(chrome::kDomDistillerScheme));
90
91 // Setup observer to inspect the RenderViewHost after committed navigation.
92 content::WebContents* contents =
93 browser()->tab_strip_model()->GetActiveWebContents();
94 LoadSuccessObserver observer(contents);
95
96 // Navigate to a URL which the source should respond to.
97 std::string url_without_scheme = "://distilled";
98 GURL url(chrome::kDomDistillerScheme + url_without_scheme);
99 ui_test_utils::NavigateToURL(browser(), url);
100
101 // A navigation should have succeeded to the correct URL.
102 ASSERT_FALSE(observer.load_failed());
103 ASSERT_TRUE(observer.finished_load());
104 ASSERT_EQ(url, observer.validated_url());
105 // Ensure no bindings.
106 const content::RenderViewHost* render_view_host = observer.render_view_host();
107 ASSERT_EQ(0, render_view_host->GetEnabledBindings());
108 }
109
110 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « chrome/browser/dom_distiller/dom_distiller_service_factory.cc ('k') | chrome/browser/history/history_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698