Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 the NPAPI unauthorized plugin infobar is: | |
| 77 // (1) Shown when the Finch trial is set to "Enabled" | |
| 78 // (2) Not shown when the Finch trial is set to "Disabled" | |
| 79 // TODO(cthomp) Remove/simplify when Finch trial is completed crbug.com/381944 | |
| 80 class UnauthorizedPluginInfoBarBrowserTestBase : public InProcessBrowserTest { | |
| 81 public: | |
| 82 explicit UnauthorizedPluginInfoBarBrowserTestBase( | |
| 83 bool infobar_trial_enabled) | |
| 84 : infobar_trial_enabled_(infobar_trial_enabled) {} | |
| 85 | |
| 86 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 87 if (infobar_trial_enabled_) { | |
| 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 void InfoBarCountTest(unsigned int number_infobars_expected, | |
| 120 Browser* browser) { | |
| 121 ServeContentTestData(); | |
| 122 content::WebContents* contents = | |
| 123 browser->tab_strip_model()->GetActiveWebContents(); | |
| 124 EXPECT_TRUE(contents != NULL); | |
| 125 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); | |
| 126 EXPECT_TRUE(infobar_service != NULL); | |
| 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 the number of infobars expected. | |
|
felt
2014/06/06 23:58:12
nit: you don't need that comment now, since it sho
| |
| 133 ASSERT_EQ(number_infobars_expected, infobar_service->infobar_count()); | |
| 134 } | |
| 135 | |
| 136 private: | |
| 137 bool infobar_trial_enabled_; | |
| 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 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, InfobarDisabled) { | |
| 169 if (!TestPageExists()) { | |
| 170 LOG(INFO) << | |
| 171 "Test skipped because plugin/quicktime.html test file wasn't found."; | |
| 172 return; | |
| 173 } | |
| 174 InfoBarCountTest(0u, browser()); | |
| 175 } | |
| 176 | |
| 177 } // namespace | |
| OLD | NEW |