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

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: Add browser_tests for infobar removal 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
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 when the UnauthorizedPluginInfoBar Finch trial is set to
77 // Default behavior (disabled) should still be correctly tested when Finch trial
78 // is over.
79 // TODO(cthomp) Remove/simplify when Finch trial is completed
80 class UnauthorizedPluginInfoBarBrowserTestBase : public InProcessBrowserTest {
81 public:
82 explicit UnauthorizedPluginInfoBarBrowserTestBase(
83 bool do_infobar_enabled_trial)
84 : do_infobar_enabled_trial_(do_infobar_enabled_trial) {}
85
86 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
87 if (do_infobar_enabled_trial_) {
88 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
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();
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 {
115 return true;
116 }
117 }
118
119 bool InfoBarCountTest(unsigned int number_infobars_expected,
120 Browser* browser) {
121 ServeContentTestData();
122 content::WebContents* contents =
123 browser->tab_strip_model()->GetActiveWebContents();
124 // ASSERT_TRUE(contents);
radhikabhar 2014/06/06 17:05:40 Do we need this comment out here?
Chris Thompson 2014/06/06 17:37:48 Uncommented and changed to EXPECT_TRUE (since thes
Bernhard Bauer 2014/06/09 17:03:18 FTR, ASSERT_ and EXPECT_ are not used to distingui
125 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
126 // ASSERT_TRUE(infobar_service);
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 // Compare to number of infobars expected
133 return (number_infobars_expected == infobar_service->infobar_count());
134 }
135
136 private:
137 bool do_infobar_enabled_trial_;
138 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarBrowserTestBase);
139 };
140
141 class InfoBarEnabledBrowserTest :
142 public UnauthorizedPluginInfoBarBrowserTestBase {
143 public:
144 InfoBarEnabledBrowserTest() :
145 UnauthorizedPluginInfoBarBrowserTestBase(true) {}
146 };
147
148 class InfoBarDisabledBrowserTest :
149 public UnauthorizedPluginInfoBarBrowserTestBase {
150 public:
151 InfoBarDisabledBrowserTest() :
152 UnauthorizedPluginInfoBarBrowserTestBase(false) {}
153 };
154
155 // When "UnauthorizedPluginInfoBar" is "Enabled", infobar for NPAPI plugin
156 // should be shown.
157 IN_PROC_BROWSER_TEST_F(InfoBarEnabledBrowserTest, InfobarEnabled) {
158 if (!TestPageExists()) {
159 LOG(INFO) <<
160 "Test skipped because plugin/quicktime.html test file wasn't found.";
161 return;
162 }
163 ASSERT_TRUE(InfoBarCountTest(1u, browser()));
164 }
165
166 // When "UnauthorizedPluginInfoBar" is "Disabled", infobar for NPAPI plugin
167 // should not be shown.
168 IN_PROC_BROWSER_TEST_F(InfoBarDisabledBrowserTest, TestDisabled) {
169 if (!TestPageExists()) {
170 LOG(INFO) <<
171 "Test skipped because plugin/quicktime.html test file wasn't found.";
172 return;
173 }
174 ASSERT_TRUE(InfoBarCountTest(0u, browser()));
175 }
176
177 } // namespace
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698