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

Side by Side Diff: chrome/browser/plugins/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: Rebased to include new blocking page action UI 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() {}
39
40 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA
41 // instead of chrome::DIR_TEST_DATA.
42 void ServeContentTestData() {
43 base::FilePath root_http;
44 PathService::Get(content::DIR_TEST_DATA, &root_http);
45 scoped_refptr<content::MessageLoopRunner> runner =
46 new content::MessageLoopRunner;
47 BrowserThread::PostTaskAndReply(
48 BrowserThread::IO, FROM_HERE,
49 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http),
50 runner->QuitClosure());
51 runner->Run();
52 }
53
54 public:
55 // Verifies that the test page exists (only present with src-internal)
56 bool TestPageExists() {
57 return base::PathExists(ui_test_utils::GetTestFilePath(
58 base::FilePath(FILE_PATH_LITERAL("plugin")),
59 base::FilePath(FILE_PATH_LITERAL("quicktime.html"))));
60 }
61
62 void InfoBarCountTest(size_t number_infobars_expected,
63 Browser* browser) {
64 ServeContentTestData();
65 content::WebContents* contents =
66 browser->tab_strip_model()->GetActiveWebContents();
67 ASSERT_TRUE(contents);
68 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
69 ASSERT_TRUE(infobar_service);
70 EXPECT_EQ(0u, infobar_service->infobar_count());
71
72 base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html"));
73 GURL url(URLRequestMockHTTPJob::GetMockUrl(path));
74 ui_test_utils::NavigateToURL(browser, url);
75 ASSERT_EQ(number_infobars_expected, infobar_service->infobar_count());
76 }
77
78 private:
79 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarBrowserTest);
80 };
81
82 // When "UnauthorizedPluginInfoBar" is "Enabled", infobar for NPAPI plugin
83 // should be shown.
84 IN_PROC_BROWSER_TEST_F(UnauthorizedPluginInfoBarBrowserTest, InfobarEnabled) {
85 if (!TestPageExists()) {
86 LOG(INFO) <<
87 "Test skipped because plugin/quicktime.html test file wasn't found.";
88 return;
89 }
90 base::FieldTrialList::CreateTrialsFromString(
91 "UnauthorizedPluginInfoBar/Enabled/",
92 base::FieldTrialList::ACTIVATE_TRIALS,
93 std::set<std::string>());
94 InfoBarCountTest(1u, browser());
95 }
96
97 // When "UnauthorizedPluginInfoBar" is "Disabled", infobar for NPAPI plugin
98 // should not be shown.
99 IN_PROC_BROWSER_TEST_F(UnauthorizedPluginInfoBarBrowserTest, InfobarDisabled) {
100 if (!TestPageExists()) {
101 LOG(INFO) <<
102 "Test skipped because plugin/quicktime.html test file wasn't found.";
103 return;
104 }
105 base::FieldTrialList::CreateTrialsFromString(
106 "UnauthorizedPluginInfoBar/Disabled/",
107 base::FieldTrialList::ACTIVATE_TRIALS,
108 std::set<std::string>());
109 InfoBarCountTest(0u, browser());
110 }
111
112 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698