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.
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/path_service.h"
11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/net/url_request_mock_util.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/render_messages.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/common/content_paths.h"
21 #include "content/public/common/content_switches.h"
22 #include "content/public/test/browser_test_utils.h"
23 #include "content/public/test/test_utils.h"
24 #include "net/test/url_request/url_request_mock_http_job.h"
27 using content::BrowserThread
;
28 using net::URLRequestMockHTTPJob
;
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
{
38 UnauthorizedPluginInfoBarBrowserTest() {}
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(
50 base::Bind(URLRequestMockHTTPJob::AddUrlHandler
,
52 make_scoped_refptr(BrowserThread::GetBlockingPool())),
53 runner
->QuitClosure());
58 // Verifies that the test page exists (only present with src-internal)
59 bool TestPageExists() {
60 return base::PathExists(ui_test_utils::GetTestFilePath(
61 base::FilePath(FILE_PATH_LITERAL("plugin")),
62 base::FilePath(FILE_PATH_LITERAL("quicktime.html"))));
65 void InfoBarCountTest(size_t number_infobars_expected
,
67 ServeContentTestData();
68 content::WebContents
* contents
=
69 browser
->tab_strip_model()->GetActiveWebContents();
70 ASSERT_TRUE(contents
);
71 InfoBarService
* infobar_service
= InfoBarService::FromWebContents(contents
);
72 ASSERT_TRUE(infobar_service
);
73 EXPECT_EQ(0u, infobar_service
->infobar_count());
75 base::FilePath
path(FILE_PATH_LITERAL("plugin/quicktime.html"));
76 GURL
url(URLRequestMockHTTPJob::GetMockUrl(path
));
77 ui_test_utils::NavigateToURL(browser
, url
);
78 ASSERT_EQ(number_infobars_expected
, infobar_service
->infobar_count());
82 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarBrowserTest
);
85 // When "UnauthorizedPluginInfoBar" is "Enabled", infobar for NPAPI plugin
87 IN_PROC_BROWSER_TEST_F(UnauthorizedPluginInfoBarBrowserTest
, InfobarEnabled
) {
88 if (!TestPageExists()) {
90 "Test skipped because plugin/quicktime.html test file wasn't found.";
93 base::FieldTrialList::CreateTrialsFromString(
94 "UnauthorizedPluginInfoBar/Enabled/",
95 base::FieldTrialList::ACTIVATE_TRIALS
,
96 std::set
<std::string
>());
97 InfoBarCountTest(1u, browser());
100 // When "UnauthorizedPluginInfoBar" is "Disabled", infobar for NPAPI plugin
101 // should not be shown.
102 IN_PROC_BROWSER_TEST_F(UnauthorizedPluginInfoBarBrowserTest
, InfobarDisabled
) {
103 if (!TestPageExists()) {
105 "Test skipped because plugin/quicktime.html test file wasn't found.";
108 base::FieldTrialList::CreateTrialsFromString(
109 "UnauthorizedPluginInfoBar/Disabled/",
110 base::FieldTrialList::ACTIVATE_TRIALS
,
111 std::set
<std::string
>());
112 InfoBarCountTest(0u, browser());