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

Unified Diff: chrome/browser/chromeos/login/captive_portal_window_browsertest.cc

Issue 15780006: Added bowser test for Captive Portal Window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added captive_portal_window_borwsertest.cc to git index. Created 7 years, 7 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/chromeos/login/captive_portal_window_browsertest.cc
diff --git a/chrome/browser/chromeos/login/captive_portal_window_browsertest.cc b/chrome/browser/chromeos/login/captive_portal_window_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf14ab35bfe78ea4e258a4d1e899959b050c885d
--- /dev/null
+++ b/chrome/browser/chromeos/login/captive_portal_window_browsertest.cc
@@ -0,0 +1,153 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// 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 "base/compiler_specific.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
+#include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
+#include "chrome/browser/chromeos/login/login_display_host_impl.h"
+#include "chromeos/chromeos_switches.h"
+
+namespace chromeos {
+
+namespace {
+
+// Stub implementation of CaptivePortalWindowProxyDelegate, does
+// nothing and used to instantiate CaptivePortalWindowProxy.
+class CaptivePortalWindowProxyStubDelegate
+ : public CaptivePortalWindowProxyDelegate {
+ public:
+ CaptivePortalWindowProxyStubDelegate(): num_portal_notifications_(0) {
+ }
+
+ virtual ~CaptivePortalWindowProxyStubDelegate() {
+ }
+
+ virtual void OnPortalDetected() OVERRIDE {
+ ++num_portal_notifications_;
+ }
+
+ int num_portal_notifications() const { return num_portal_notifications_; }
+
+ private:
+ int num_portal_notifications_;
+};
+
+} // namespace
+
+class CaptivePortalWindowTest : public CrosInProcessBrowserTest {
+ protected:
+ void ShowIfRedirected() {
+ captive_portal_window_proxy_->ShowIfRedirected();
+ }
+
+ void Show() {
+ captive_portal_window_proxy_->Show();
+ }
+
+ void Close() {
+ captive_portal_window_proxy_->Close();
+ }
+
+ void OnRedirected() {
+ captive_portal_window_proxy_->OnRedirected();
+ }
+
+ void OnOriginalURLLoaded() {
+ captive_portal_window_proxy_->OnOriginalURLLoaded();
+ }
+
+ void CheckState(bool is_shown, int num_portal_notifications) {
+ ASSERT_EQ(is_shown, captive_portal_window_proxy_->IsShown());
+ ASSERT_EQ(num_portal_notifications, delegate_.num_portal_notifications());
+ }
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
+ command_line->AppendSwitch(chromeos::switches::kLoginManager);
+ }
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ CHECK(LoginDisplayHostImpl::default_host());
+ gfx::NativeWindow native_window =
+ LoginDisplayHostImpl::default_host()->GetNativeWindow();
+ captive_portal_window_proxy_.reset(
+ new CaptivePortalWindowProxy(&delegate_, native_window));
+ }
+
+ private:
+ scoped_ptr<CaptivePortalWindowProxy> captive_portal_window_proxy_;
+ CaptivePortalWindowProxyStubDelegate delegate_;
+};
+
+IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, ShowClose) {
+ CheckState(false, 0);
+
+ Show();
+ CheckState(true, 0);
+
+ Close();
+ CheckState(false, 0);
+}
+
+IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, OnRedirected) {
+ CheckState(false, 0);
+
+ ShowIfRedirected();
+ CheckState(false, 0);
+
+ OnRedirected();
+ CheckState(true, 1);
+
+ Close();
+ CheckState(false, 1);
+}
+
+IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, OnOriginalURLLoaded) {
+ CheckState(false, 0);
+
+ ShowIfRedirected();
+ CheckState(false, 0);
+
+ OnRedirected();
+ CheckState(true, 1);
+
+ OnOriginalURLLoaded();
+ CheckState(false, 1);
+}
+
+IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, MultipleCalls) {
+ CheckState(false, 0);
+
+ ShowIfRedirected();
+ CheckState(false, 0);
+
+ Show();
+ CheckState(true, 0);
+
+ Close();
+ CheckState(false, 0);
+
+ OnRedirected();
+ CheckState(true, 1);
Nikita (slow) 2013/05/27 16:55:35 It makes sense to improve UX which this test shows
ygorshenin1 2013/05/28 10:04:14 Done.
+
+ OnOriginalURLLoaded();
+ CheckState(false, 1);
+
+ Show();
+ CheckState(true, 1);
+
+ OnRedirected();
+ CheckState(true, 2);
+
+ Close();
+ CheckState(false, 2);
+
+ OnOriginalURLLoaded();
+ CheckState(false, 2);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698