OLD | NEW |
---|---|
(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 field_trial_list(NULL); | |
Bernhard Bauer
2014/06/11 08:37:28
I think you could make this a member?
Chris Thompson
2014/06/11 19:47:09
Turns out I don't need to initialize it at all. No
| |
91 base::FieldTrialList::CreateTrialsFromString( | |
92 "UnauthorizedPluginInfoBar/Enabled/", | |
93 base::FieldTrialList::ACTIVATE_TRIALS, | |
94 std::set<std::string>()); | |
95 InfoBarCountTest(1u, browser()); | |
96 } | |
97 | |
98 // When "UnauthorizedPluginInfoBar" is "Disabled", infobar for NPAPI plugin | |
99 // should not be shown. | |
100 IN_PROC_BROWSER_TEST_F(UnauthorizedPluginInfoBarBrowserTest, InfobarDisabled) { | |
101 if (!TestPageExists()) { | |
102 LOG(INFO) << | |
103 "Test skipped because plugin/quicktime.html test file wasn't found."; | |
104 return; | |
105 } | |
106 base::FieldTrialList field_trial_list(NULL); | |
107 base::FieldTrialList::CreateTrialsFromString( | |
108 "UnauthorizedPluginInfoBar/Disabled/", | |
109 base::FieldTrialList::ACTIVATE_TRIALS, | |
110 std::set<std::string>()); | |
111 InfoBarCountTest(0u, browser()); | |
112 } | |
113 | |
114 } // namespace | |
OLD | NEW |