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

Unified Diff: chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc

Issue 418043002: Add test for showing confirmation dialog for unsecure signin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added comments Created 6 years, 5 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/browser/ui/webui/signin/inline_login_ui_browsertest.cc
diff --git a/chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc b/chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc
index 13a9a096b0c34ae0c29970534a60e13aa5233627..de3d48e4a13a2e6bc50f14fa9c933a06defe6143 100644
--- a/chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc
@@ -2,15 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/webui/signin/inline_login_ui.h"
+#include "chrome/browser/ui/webui/signin/login_ui_service.h"
+#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/session_storage_namespace.h"
#include "content/public/browser/storage_partition.h"
@@ -19,12 +25,18 @@
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
+#include "google_apis/gaia/fake_gaia.h"
+#include "google_apis/gaia/gaia_switches.h"
#include "net/base/url_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/embedded_test_server/http_request.h"
+#include "net/test/embedded_test_server/http_response.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
+using ::testing::Invoke;
+using ::testing::InvokeWithoutArgs;
namespace {
@@ -65,6 +77,11 @@ class FooWebUIProvider
const GURL& url));
};
+class MockLoginUIObserver : public LoginUIService::Observer {
+ public:
+ MOCK_METHOD0(UntrustedSigninUIShown, void());
+};
+
const char kFooWebUIURL[] = "chrome://foo/";
} // namespace
@@ -147,8 +164,27 @@ class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest {
} while (message != "\"ready\"");
}
+ // Executes JavaScript code in the auth iframe hosted by gaia_auth extension.
+ void ExecuteJsInSigninFrame(const std::string& js) {
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_TRUE(content::ExecuteScript(InlineLoginUI::GetAuthIframe(
+ web_contents, GURL(), "signin-frame"), js));
+ }
+
+ protected:
+ FakeGaia fake_gaia_;
+
private:
+ virtual void SetUp() OVERRIDE {
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
xiyuan 2014/07/25 18:07:23 We cannot do it like this. Check out the comments
guohui 2014/08/07 19:53:34 Done.
+ InProcessBrowserTest::SetUp();
+ }
+
virtual void SetUpOnMainThread() OVERRIDE {
+ embedded_test_server()->RegisterRequestHandler(
+ base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
+
content::WebUIControllerFactory::UnregisterFactoryForTesting(
ChromeWebUIControllerFactory::GetInstance());
test_factory_.reset(new TestChromeWebUIControllerFactory);
@@ -164,6 +200,15 @@ class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest {
test_factory_.reset();
}
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ const GURL& base_url = embedded_test_server()->base_url();
+ command_line->AppendSwitchASCII(::switches::kGaiaUrl, base_url.spec());
+ command_line->AppendSwitchASCII(::switches::kLsoUrl, base_url.spec());
+ command_line->AppendSwitchASCII(::switches::kGoogleApisUrl,
+ base_url.spec());
+ fake_gaia_.Initialize();
+ }
+
FooWebUIProvider foo_provider_;
scoped_ptr<TestChromeWebUIControllerFactory> test_factory_;
};
@@ -197,7 +242,6 @@ IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) {
// TODO(guohui): flaky on trybot crbug/364759.
IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest,
MAYBE_TopFrameNavigationDisallowed) {
- ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
// Loads into gaia iframe a web page that attempts to deframe on load.
GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html"));
GURL url(net::AppendOrReplaceQueryParameter(
@@ -239,3 +283,34 @@ IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest,
EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL());
}
+
+#if !defined(OS_CHROMEOS)
+IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest,
+ ConfirmationRequiredForNonsecureSignin) {
+ fake_gaia_.SetFakeMergeSessionParamsForEmail("email");
+
+ // Navigates to the Chrome signin page which loads the fake gaia auth page.
+ // Since the fake gaia auth page is served over HTTP, thus expects to see an
+ // untrusted signin confirmation dialog upon submitting credentials below.
+ ui_test_utils::NavigateToURL(
+ browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false));
+ WaitUntilUIReady();
+
+ MockLoginUIObserver observer;
+ LoginUIServiceFactory::GetForProfile(browser()->profile())
+ ->AddObserver(&observer);
+ base::RunLoop run_loop;
+ EXPECT_CALL(observer, UntrustedSigninUIShown())
+ .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
+
+ content::WebContents* contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ std::string js =
+ "document.getElementById('Email').value = 'email';"
+ "document.getElementById('Passwd').value = 'password';"
+ "document.getElementById('signIn').click();";
+ ExecuteJsInSigninFrame(js);
+
+ run_loop.Run();
+}
+#endif // OS_CHROMEOS

Powered by Google App Engine
This is Rietveld 408576698