Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / password_manager_internals / password_manager_internals_ui_browsertest.cc
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/command_line.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8 #include "chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "chrome/test/base/web_ui_browsertest.h"
12 #include "components/password_manager/core/common/password_manager_switches.h"
13 #include "content/public/browser/web_contents.h"
14
15 class PasswordManagerInternalsWebUIBrowserTest : public WebUIBrowserTest {
16  public:
17   PasswordManagerInternalsWebUIBrowserTest();
18   virtual ~PasswordManagerInternalsWebUIBrowserTest();
19
20   virtual void SetUpOnMainThread() OVERRIDE;
21   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
22
23  protected:
24   content::WebContents* GetWebContents();
25
26   // Opens a new tab, and navigates to the internals page in that. Also assigns
27   // the corresponding UI controller to |controller_|.
28   void OpenNewTabWithTheInternalsPage();
29
30   PasswordManagerInternalsUI* controller() {
31     return controller_;
32   };
33
34  private:
35   PasswordManagerInternalsUI* controller_;
36 };
37
38 PasswordManagerInternalsWebUIBrowserTest::
39     PasswordManagerInternalsWebUIBrowserTest()
40     : controller_(NULL) {}
41
42 PasswordManagerInternalsWebUIBrowserTest::
43     ~PasswordManagerInternalsWebUIBrowserTest() {}
44
45 void PasswordManagerInternalsWebUIBrowserTest::SetUpOnMainThread() {
46   WebUIBrowserTest::SetUpOnMainThread();
47   OpenNewTabWithTheInternalsPage();
48 }
49
50 void PasswordManagerInternalsWebUIBrowserTest::SetUpCommandLine(
51     CommandLine* command_line) {
52   command_line->AppendSwitch(
53       password_manager::switches::kEnablePasswordManagerInternalsUI);
54 }
55
56 content::WebContents*
57 PasswordManagerInternalsWebUIBrowserTest::GetWebContents() {
58   return browser()->tab_strip_model()->GetActiveWebContents();
59 }
60
61 void
62 PasswordManagerInternalsWebUIBrowserTest::OpenNewTabWithTheInternalsPage() {
63   std::string url_string("chrome://");
64   url_string += chrome::kChromeUIPasswordManagerInternalsHost;
65   ui_test_utils::NavigateToURLWithDisposition(
66       browser(),
67       GURL(url_string),
68       NEW_FOREGROUND_TAB,
69       ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
70   controller_ = static_cast<PasswordManagerInternalsUI*>(
71       GetWebContents()->GetWebUI()->GetController());
72   AddLibrary(base::FilePath(
73       FILE_PATH_LITERAL("password_manager_internals_browsertest.js")));
74 }
75
76 IN_PROC_BROWSER_TEST_F(PasswordManagerInternalsWebUIBrowserTest,
77                        LogSavePasswordProgress) {
78   controller()->LogSavePasswordProgress("<script> text for testing");
79   ASSERT_TRUE(RunJavascriptTest("testLogText"));
80 }
81
82 // Test that if two tabs with the internals page are open, the second displays
83 // the same logs. In particular, this checks that both the second tab gets the
84 // logs created before the second tab was opened, and also that the second tab
85 // waits with displaying until the internals page is ready (trying to display
86 // the old logs just on construction time would fail).
87 // TODO(vabr): Disabled until multiple tabs with the internals page can exist
88 // without crashing.
89 IN_PROC_BROWSER_TEST_F(PasswordManagerInternalsWebUIBrowserTest,
90                        DISABLED_LogSavePasswordProgress_MultipleTabsIdentical) {
91   // First, open one tab with the internals page, and log something.
92   controller()->LogSavePasswordProgress("<script> text for testing");
93   ASSERT_TRUE(RunJavascriptTest("testLogText"));
94   // Now open a second tab with the internals page, but do not log anything.
95   OpenNewTabWithTheInternalsPage();
96   // The previously logged text should have made it to the page.
97   ASSERT_TRUE(RunJavascriptTest("testLogText"));
98 }