Index: chrome/renderer/chrome_content_renderer_client_browsertest.cc |
diff --git a/chrome/renderer/chrome_content_renderer_client_browsertest.cc b/chrome/renderer/chrome_content_renderer_client_browsertest.cc |
index 603d78e8f4c489d97f854dc53514a67c204d3139..af115a788e703d44222ed30d2fc65d12c7bef585 100644 |
--- a/chrome/renderer/chrome_content_renderer_client_browsertest.cc |
+++ b/chrome/renderer/chrome_content_renderer_client_browsertest.cc |
@@ -6,14 +6,32 @@ |
#include <vector> |
+#include "base/bind.h" |
#include "base/command_line.h" |
+#include "base/files/file_path.h" |
+#include "base/path_service.h" |
+#include "chrome/browser/infobars/infobar_service.h" |
+#include "chrome/browser/net/url_request_mock_util.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/render_messages.h" |
#include "chrome/renderer/chrome_content_renderer_client.h" |
#include "chrome/test/base/chrome_render_view_test.h" |
+#include "chrome/test/base/in_process_browser_test.h" |
+#include "chrome/test/base/ui_test_utils.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/common/content_paths.h" |
+#include "content/public/common/content_switches.h" |
+#include "content/public/test/browser_test_utils.h" |
+#include "content/public/test/test_utils.h" |
+#include "content/test/net/url_request_mock_http_job.h" |
#include "third_party/WebKit/public/web/WebLocalFrame.h" |
#include "url/gurl.h" |
+using content::BrowserThread; |
+using content::URLRequestMockHTTPJob; |
+ |
typedef ChromeRenderViewTest InstantProcessNavigationTest; |
// Tests that renderer-initiated navigations from an Instant render process get |
@@ -52,3 +70,107 @@ TEST_F(InstantProcessNavigationTest, ForkForNavigationsToSearchURLs) { |
GetMainFrame(), GURL("http://example.com/"), "GET", false, false, |
&unused)); |
} |
+ |
+namespace { |
+ |
+// Tests that the NPAPI unauthorized plugin infobar is: |
+// (1) Shown when the Finch trial is set to "Enabled" |
+// (2) Not shown when the Finch trial is set to "Disabled" |
+// TODO(cthomp) Remove/simplify when Finch trial is completed crbug.com/381944 |
Bernhard Bauer
2014/06/09 17:03:18
Nit: The recommended format for TODOs is TODO(ldap
|
+class UnauthorizedPluginInfoBarBrowserTestBase : public InProcessBrowserTest { |
+ public: |
+ explicit UnauthorizedPluginInfoBarBrowserTestBase( |
+ bool infobar_trial_enabled) |
+ : infobar_trial_enabled_(infobar_trial_enabled) {} |
Bernhard Bauer
2014/06/09 17:03:18
Nit: indent two more spaces.
|
+ |
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
+ if (infobar_trial_enabled_) { |
+ command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
Bernhard Bauer
2014/06/09 17:03:18
You can enable field trials directly with FieldTri
|
+ "UnauthorizedPluginInfoBar/Enabled/"); |
+ } else { |
+ command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
+ "UnauthorizedPluginInfoBar/Disabled/"); |
+ } |
+ } |
+ |
+ // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA |
+ // instead of chrome::DIR_TEST_DATA. |
+ void ServeContentTestData() { |
+ base::FilePath root_http; |
+ PathService::Get(content::DIR_TEST_DATA, &root_http); |
+ BrowserThread::PostTaskAndReply( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http), |
+ base::MessageLoop::current()->QuitWhenIdleClosure()); |
+ content::RunMessageLoop(); |
Bernhard Bauer
2014/06/09 17:03:18
Prefer a MessageLoopRunner with an explicit quit c
|
+ } |
+ |
+ // Verifies that the test page exists (only present with src-internal) |
+ bool TestPageExists() { |
+ if (!base::PathExists(ui_test_utils::GetTestFilePath( |
+ base::FilePath(FILE_PATH_LITERAL("plugin")), |
+ base::FilePath(FILE_PATH_LITERAL("quicktime.html"))))) { |
+ return false; |
+ } else { |
Bernhard Bauer
2014/06/09 17:03:18
`else` isn't necessary if the `if` branch returns.
|
+ return true; |
+ } |
+ } |
+ |
+ void InfoBarCountTest(unsigned int number_infobars_expected, |
Bernhard Bauer
2014/06/09 17:03:18
Don't use `unsigned int`, use a regular int or a s
|
+ Browser* browser) { |
+ ServeContentTestData(); |
+ content::WebContents* contents = |
+ browser->tab_strip_model()->GetActiveWebContents(); |
+ EXPECT_TRUE(contents != NULL); |
Bernhard Bauer
2014/06/09 17:03:18
If contents is actually NULL, you will crash below
|
+ InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); |
+ EXPECT_TRUE(infobar_service != NULL); |
+ EXPECT_EQ(0u, infobar_service->infobar_count()); |
+ |
+ base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html")); |
+ GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
+ ui_test_utils::NavigateToURL(browser, url); |
+ ASSERT_EQ(number_infobars_expected, infobar_service->infobar_count()); |
+ } |
+ |
+ private: |
+ bool infobar_trial_enabled_; |
+ DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarBrowserTestBase); |
+}; |
+ |
+class InfoBarEnabledBrowserTest : |
Bernhard Bauer
2014/06/09 17:03:18
Do you actually need these two test fixtures? Just
|
+ public UnauthorizedPluginInfoBarBrowserTestBase { |
+ public: |
+ InfoBarEnabledBrowserTest() : |
+ UnauthorizedPluginInfoBarBrowserTestBase(true) {} |
+}; |
+ |
+class InfoBarDisabledBrowserTest : |
+ public UnauthorizedPluginInfoBarBrowserTestBase { |
+ public: |
+ InfoBarDisabledBrowserTest() : |
+ UnauthorizedPluginInfoBarBrowserTestBase(false) {} |
+}; |
+ |
+// When "UnauthorizedPluginInfoBar" is "Enabled", infobar for NPAPI plugin |
+// should be shown. |
+IN_PROC_BROWSER_TEST_F(InfoBarEnabledBrowserTest, InfobarEnabled) { |
+ if (!TestPageExists()) { |
+ LOG(INFO) << |
+ "Test skipped because plugin/quicktime.html test file wasn't found."; |
+ return; |
+ } |
+ InfoBarCountTest(1u, browser()); |
+} |
+ |
+// When "UnauthorizedPluginInfoBar" is "Disabled", infobar for NPAPI plugin |
+// should not be shown. |
+IN_PROC_BROWSER_TEST_F(InfoBarDisabledBrowserTest, InfobarDisabled) { |
+ if (!TestPageExists()) { |
+ LOG(INFO) << |
+ "Test skipped because plugin/quicktime.html test file wasn't found."; |
+ return; |
+ } |
+ InfoBarCountTest(0u, browser()); |
+} |
+ |
+} // namespace |