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

Side by Side Diff: chrome/browser/npapi_infobar_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: Move tests out of renderer, address various reviewer comments 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
(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 "base/bind.h"
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/path_service.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/net/url_request_mock_util.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/render_messages.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/common/content_paths.h"
20 #include "content/public/common/content_switches.h"
21 #include "content/public/test/browser_test_utils.h"
22 #include "content/public/test/test_utils.h"
23 #include "content/test/net/url_request_mock_http_job.h"
24 #include "url/gurl.h"
25
26 using content::BrowserThread;
27 using content::URLRequestMockHTTPJob;
28
29
30 namespace {
31
32 // Tests that the NPAPI unauthorized plugin infobar is:
33 // (1) Shown when the Finch trial is set to "Enabled"
34 // (2) Not shown when the Finch trial is set to "Disabled"
35 // TODO(cthomp): Remove/simplify when Finch trial is completed crbug.com/381944
36 class UnauthorizedPluginInfoBarBrowserTest : public InProcessBrowserTest {
37 protected:
38 UnauthorizedPluginInfoBarBrowserTest() : infobar_trial_enabled_(false) {}
39
40 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
41 if (infobar_trial_enabled_)
42 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
43 "UnauthorizedPluginInfoBar/Enabled/");
44 else
45 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
46 "UnauthorizedPluginInfoBar/Disabled/");
47 }
48
49 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA
50 // instead of chrome::DIR_TEST_DATA.
51 void ServeContentTestData() {
52 base::FilePath root_http;
53 PathService::Get(content::DIR_TEST_DATA, &root_http);
54 scoped_refptr<content::MessageLoopRunner> runner =
55 new content::MessageLoopRunner;
56 BrowserThread::PostTaskAndReply(
57 BrowserThread::IO, FROM_HERE,
58 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http),
59 runner->QuitClosure());
60 runner->Run();
61 }
62
63 public:
64 // Verifies that the test page exists (only present with src-internal)
65 bool TestPageExists() {
66 return base::PathExists(ui_test_utils::GetTestFilePath(
67 base::FilePath(FILE_PATH_LITERAL("plugin")),
68 base::FilePath(FILE_PATH_LITERAL("quicktime.html"))));
69 }
70
71 void InfoBarCountTest(size_t number_infobars_expected,
72 Browser* browser) {
73 ServeContentTestData();
74 content::WebContents* contents =
75 browser->tab_strip_model()->GetActiveWebContents();
76 ASSERT_TRUE(contents);
77 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
78 ASSERT_TRUE(infobar_service);
79 EXPECT_EQ(0u, infobar_service->infobar_count());
80
81 base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html"));
82 GURL url(URLRequestMockHTTPJob::GetMockUrl(path));
83 ui_test_utils::NavigateToURL(browser, url);
84 ASSERT_EQ(number_infobars_expected, infobar_service->infobar_count());
85 }
86
87 void set_infobar_trial_enabled(bool enabled) {
88 infobar_trial_enabled_ = enabled;
89 }
90
91 private:
92 bool infobar_trial_enabled_;
93 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarBrowserTest);
94 };
95
96 // When "UnauthorizedPluginInfoBar" is "Enabled", infobar for NPAPI plugin
97 // should be shown.
98 IN_PROC_BROWSER_TEST_F(UnauthorizedPluginInfoBarBrowserTest, InfobarEnabled) {
99 if (!TestPageExists()) {
100 LOG(INFO) <<
101 "Test skipped because plugin/quicktime.html test file wasn't found.";
102 return;
103 }
104 set_infobar_trial_enabled(true);
105 InfoBarCountTest(1u, browser());
106 }
107
108 // When "UnauthorizedPluginInfoBar" is "Disabled", infobar for NPAPI plugin
109 // should not be shown.
110 IN_PROC_BROWSER_TEST_F(UnauthorizedPluginInfoBarBrowserTest, InfobarDisabled) {
111 if (!TestPageExists()) {
112 LOG(INFO) <<
113 "Test skipped because plugin/quicktime.html test file wasn't found.";
114 return;
115 }
116 set_infobar_trial_enabled(false);
117 InfoBarCountTest(0u, browser());
118 }
119
120 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698