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

Unified Diff: chrome/renderer/chrome_content_renderer_client_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: Added back ASSERTs as EXPECTs for better test debug-ability. 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 side-by-side diff with in-line comments
Download patch
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..0b8e3e87a3259424ffea9aba2f8d95727e6c2d1f 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,108 @@ TEST_F(InstantProcessNavigationTest, ForkForNavigationsToSearchURLs) {
GetMainFrame(), GURL("http://example.com/"), "GET", false, false,
&unused));
}
+
+namespace {
+
+// Tests that when the UnauthorizedPluginInfoBar Finch trial is set to
+// Default behavior (disabled) should still be correctly tested when Finch trial
+// is over.
felt 2014/06/06 22:55:33 my brain can't quite parse that comment, can you p
Chris Thompson 2014/06/06 23:49:37 Agreed. Deleted and rewritten to explain the two c
+// TODO(cthomp) Remove/simplify when Finch trial is completed
felt 2014/06/06 22:55:33 Please file a bug for this (a removal bug), assign
Chris Thompson 2014/06/06 23:49:37 Updated comment, linking to crbug.com/381944
+class UnauthorizedPluginInfoBarBrowserTestBase : public InProcessBrowserTest {
+ public:
+ explicit UnauthorizedPluginInfoBarBrowserTestBase(
+ bool do_infobar_enabled_trial)
felt 2014/06/06 22:55:33 maybe try naming something like |infobar_trial_ena
Chris Thompson 2014/06/06 23:49:37 Done.
+ : do_infobar_enabled_trial_(do_infobar_enabled_trial) {}
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ if (do_infobar_enabled_trial_) {
+ command_line->AppendSwitchASCII(switches::kForceFieldTrials,
+ "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();
+ }
+
+ // 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 {
+ return true;
+ }
+ }
+
+ bool InfoBarCountTest(unsigned int number_infobars_expected,
+ Browser* browser) {
+ ServeContentTestData();
+ content::WebContents* contents =
+ browser->tab_strip_model()->GetActiveWebContents();
+ EXPECT_TRUE(contents != NULL);
+ 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);
+ // Compare to number of infobars expected
felt 2014/06/06 22:55:33 why not do EXPECT_EQ instead of returning like thi
Chris Thompson 2014/06/06 23:49:37 No particular reason. Changed to ASSERT_EQ inside
+ return (number_infobars_expected == infobar_service->infobar_count());
+ }
+
+ private:
+ bool do_infobar_enabled_trial_;
+ DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarBrowserTestBase);
+};
+
+class InfoBarEnabledBrowserTest :
+ 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;
+ }
+ ASSERT_TRUE(InfoBarCountTest(1u, browser()));
+}
+
+// When "UnauthorizedPluginInfoBar" is "Disabled", infobar for NPAPI plugin
+// should not be shown.
+IN_PROC_BROWSER_TEST_F(InfoBarDisabledBrowserTest, TestDisabled) {
felt 2014/06/06 22:55:34 would be good for symmetry here -- InfobarEnabled,
Chris Thompson 2014/06/06 23:49:37 Missed that one. Fixed.
+ if (!TestPageExists()) {
+ LOG(INFO) <<
+ "Test skipped because plugin/quicktime.html test file wasn't found.";
+ return;
+ }
+ ASSERT_TRUE(InfoBarCountTest(0u, browser()));
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698