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

Side by Side Diff: chrome/renderer/chrome_content_renderer_client_browsertest.cc

Issue 300873002: Removed NPAPI plugin infobar, with Finch trial gate (disabled by default). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary comment Created 6 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h"
12 #include "base/path_service.h"
13 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/net/url_request_mock_util.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/render_messages.h" 18 #include "chrome/common/render_messages.h"
12 #include "chrome/renderer/chrome_content_renderer_client.h" 19 #include "chrome/renderer/chrome_content_renderer_client.h"
13 #include "chrome/test/base/chrome_render_view_test.h" 20 #include "chrome/test/base/chrome_render_view_test.h"
21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/common/content_paths.h"
25 #include "content/public/common/content_switches.h"
26 #include "content/public/test/browser_test_utils.h"
27 #include "content/public/test/test_utils.h"
28 #include "content/test/net/url_request_mock_http_job.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h" 29 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 #include "url/gurl.h" 30 #include "url/gurl.h"
16 31
32 using content::BrowserThread;
33 using content::URLRequestMockHTTPJob;
34
17 typedef ChromeRenderViewTest InstantProcessNavigationTest; 35 typedef ChromeRenderViewTest InstantProcessNavigationTest;
18 36
19 // Tests that renderer-initiated navigations from an Instant render process get 37 // Tests that renderer-initiated navigations from an Instant render process get
20 // bounced back to the browser to be rebucketed into a non-Instant renderer if 38 // bounced back to the browser to be rebucketed into a non-Instant renderer if
21 // necessary. 39 // necessary.
22 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) { 40 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) {
23 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kInstantProcess); 41 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kInstantProcess);
24 bool unused; 42 bool unused;
25 ChromeContentRendererClient* client = 43 ChromeContentRendererClient* client =
26 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); 44 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get());
(...skipping 18 matching lines...) Expand all
45 EXPECT_TRUE(client->ShouldFork( 63 EXPECT_TRUE(client->ShouldFork(
46 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, 64 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false,
47 &unused)); 65 &unused));
48 EXPECT_TRUE(client->ShouldFork( 66 EXPECT_TRUE(client->ShouldFork(
49 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, 67 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false,
50 false, &unused)); 68 false, &unused));
51 EXPECT_FALSE(client->ShouldFork( 69 EXPECT_FALSE(client->ShouldFork(
52 GetMainFrame(), GURL("http://example.com/"), "GET", false, false, 70 GetMainFrame(), GURL("http://example.com/"), "GET", false, false,
53 &unused)); 71 &unused));
54 } 72 }
73
74 namespace {
75
76 // Tests that the NPAPI unauthorized plugin infobar is:
77 // (1) Shown when the Finch trial is set to "Enabled"
78 // (2) Not shown when the Finch trial is set to "Disabled"
79 // TODO(cthomp) Remove/simplify when Finch trial is completed crbug.com/381944
Bernhard Bauer 2014/06/09 17:03:18 Nit: The recommended format for TODOs is TODO(ldap
80 class UnauthorizedPluginInfoBarBrowserTestBase : public InProcessBrowserTest {
81 public:
82 explicit UnauthorizedPluginInfoBarBrowserTestBase(
83 bool infobar_trial_enabled)
84 : infobar_trial_enabled_(infobar_trial_enabled) {}
Bernhard Bauer 2014/06/09 17:03:18 Nit: indent two more spaces.
85
86 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
87 if (infobar_trial_enabled_) {
88 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
Bernhard Bauer 2014/06/09 17:03:18 You can enable field trials directly with FieldTri
89 "UnauthorizedPluginInfoBar/Enabled/");
90 } else {
91 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
92 "UnauthorizedPluginInfoBar/Disabled/");
93 }
94 }
95
96 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA
97 // instead of chrome::DIR_TEST_DATA.
98 void ServeContentTestData() {
99 base::FilePath root_http;
100 PathService::Get(content::DIR_TEST_DATA, &root_http);
101 BrowserThread::PostTaskAndReply(
102 BrowserThread::IO, FROM_HERE,
103 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http),
104 base::MessageLoop::current()->QuitWhenIdleClosure());
105 content::RunMessageLoop();
Bernhard Bauer 2014/06/09 17:03:18 Prefer a MessageLoopRunner with an explicit quit c
106 }
107
108 // Verifies that the test page exists (only present with src-internal)
109 bool TestPageExists() {
110 if (!base::PathExists(ui_test_utils::GetTestFilePath(
111 base::FilePath(FILE_PATH_LITERAL("plugin")),
112 base::FilePath(FILE_PATH_LITERAL("quicktime.html"))))) {
113 return false;
114 } else {
Bernhard Bauer 2014/06/09 17:03:18 `else` isn't necessary if the `if` branch returns.
115 return true;
116 }
117 }
118
119 void InfoBarCountTest(unsigned int number_infobars_expected,
Bernhard Bauer 2014/06/09 17:03:18 Don't use `unsigned int`, use a regular int or a s
120 Browser* browser) {
121 ServeContentTestData();
122 content::WebContents* contents =
123 browser->tab_strip_model()->GetActiveWebContents();
124 EXPECT_TRUE(contents != NULL);
Bernhard Bauer 2014/06/09 17:03:18 If contents is actually NULL, you will crash below
125 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
126 EXPECT_TRUE(infobar_service != NULL);
127 EXPECT_EQ(0u, infobar_service->infobar_count());
128
129 base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html"));
130 GURL url(URLRequestMockHTTPJob::GetMockUrl(path));
131 ui_test_utils::NavigateToURL(browser, url);
132 ASSERT_EQ(number_infobars_expected, infobar_service->infobar_count());
133 }
134
135 private:
136 bool infobar_trial_enabled_;
137 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarBrowserTestBase);
138 };
139
140 class InfoBarEnabledBrowserTest :
Bernhard Bauer 2014/06/09 17:03:18 Do you actually need these two test fixtures? Just
141 public UnauthorizedPluginInfoBarBrowserTestBase {
142 public:
143 InfoBarEnabledBrowserTest() :
144 UnauthorizedPluginInfoBarBrowserTestBase(true) {}
145 };
146
147 class InfoBarDisabledBrowserTest :
148 public UnauthorizedPluginInfoBarBrowserTestBase {
149 public:
150 InfoBarDisabledBrowserTest() :
151 UnauthorizedPluginInfoBarBrowserTestBase(false) {}
152 };
153
154 // When "UnauthorizedPluginInfoBar" is "Enabled", infobar for NPAPI plugin
155 // should be shown.
156 IN_PROC_BROWSER_TEST_F(InfoBarEnabledBrowserTest, InfobarEnabled) {
157 if (!TestPageExists()) {
158 LOG(INFO) <<
159 "Test skipped because plugin/quicktime.html test file wasn't found.";
160 return;
161 }
162 InfoBarCountTest(1u, browser());
163 }
164
165 // When "UnauthorizedPluginInfoBar" is "Disabled", infobar for NPAPI plugin
166 // should not be shown.
167 IN_PROC_BROWSER_TEST_F(InfoBarDisabledBrowserTest, InfobarDisabled) {
168 if (!TestPageExists()) {
169 LOG(INFO) <<
170 "Test skipped because plugin/quicktime.html test file wasn't found.";
171 return;
172 }
173 InfoBarCountTest(0u, browser());
174 }
175
176 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698