Commit 14a6d8de authored by Danan S's avatar Danan S Committed by Commit Bot

Reland "Automated tests for Add Supervision flow ChromeOS code"

This reverts commit 441c06d9.

Reason for revert: Reland changes after disabling test for MSan builds.
The root issue is a bug that causes a flaky initialization  behavior
in the <webview> element in MSan builds (https://crbug.com/1002560)

Also, added a new unit test from tobyhuang@ that was dependent on
the original reverted CL.

Original change's description:
> Revert "Automated tests for Add Supervision flow ChromeOS code"
>
> This reverts commit 9f7c76d0.
>
> Reason for revert:
> AddSupervisionBrowserTest.ShowConfirmSignoutDialog
> AddSupervisionBrowserTest.URLParameters
> failing on Linux ChromiumOS MSan Tests, see
> https://findit-for-me.appspot.com/waterfall/failure?url=https://build.chromium.org/p/chromium.memory/builders/Linux%20ChromiumOS%20MSan%20Tests/builds/15000
>
> Original change's description:
> > Automated tests for Add Supervision flow ChromeOS code
> >
> > This required modifying the classes under test, including
> > AddSupervisionHandler, AddSupervisionUI, and ConfirmSignoutDialog
> > to allow them to be tested.
> >
> > Bug:982543
> >
> > Change-Id: I3bebada137fe57a63ca090c788fa5a0cb317d22b
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1771387
> > Commit-Queue: Danan S <danan@chromium.org>
> > Reviewed-by: Michael Giuffrida <michaelpg@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#693320}
>
> TBR=michaelpg@chromium.org,danan@chromium.org
>
> Change-Id: Ibe6189ed52f32afb62cdfabbf890857e474de6ea
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 982543
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787417
> Reviewed-by: Olga Sharonova <olka@chromium.org>
> Commit-Queue: Olga Sharonova <olka@chromium.org>
> Auto-Submit: Olga Sharonova <olka@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#693571}

Change-Id: I4d2c19c229923a5bd1acb246f8e9d4d1b2ccb9af
Bug: 982543
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787613
Commit-Queue: Dan S <danan@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695835}
parent a2350063
...@@ -33,7 +33,6 @@ function isAllowedRequest(requestDetails) { ...@@ -33,7 +33,6 @@ function isAllowedRequest(requestDetails) {
requestUrl.host.endsWith('.' + allowedHost)); requestUrl.host.endsWith('.' + allowedHost));
} }
let server = null;
const addSupervisionHandler = const addSupervisionHandler =
addSupervision.mojom.AddSupervisionHandler.getRemote(); addSupervision.mojom.AddSupervisionHandler.getRemote();
...@@ -42,7 +41,7 @@ Polymer({ ...@@ -42,7 +41,7 @@ Polymer({
/** Attempts to close the dialog */ /** Attempts to close the dialog */
closeDialog_: function() { closeDialog_: function() {
server.requestClose(); this.server.requestClose();
}, },
/** @override */ /** @override */
...@@ -95,7 +94,8 @@ Polymer({ ...@@ -95,7 +94,8 @@ Polymer({
webview.src = url.toString(); webview.src = url.toString();
// Set up the server. // Set up the server.
server = new AddSupervisionAPIServer(webview, url, eventOriginFilter); this.server =
new AddSupervisionAPIServer(webview, url, eventOriginFilter);
}); });
}, },
}); });
...@@ -31,10 +31,10 @@ namespace chromeos { ...@@ -31,10 +31,10 @@ namespace chromeos {
AddSupervisionHandler::AddSupervisionHandler( AddSupervisionHandler::AddSupervisionHandler(
add_supervision::mojom::AddSupervisionHandlerRequest request, add_supervision::mojom::AddSupervisionHandlerRequest request,
content::WebUI* web_ui, content::WebUI* web_ui,
signin::IdentityManager* identity_manager,
Delegate* delegate) Delegate* delegate)
: web_ui_(web_ui), : web_ui_(web_ui),
identity_manager_( identity_manager_(identity_manager),
IdentityManagerFactory::GetForProfile(Profile::FromWebUI(web_ui))),
binding_(this, std::move(request)), binding_(this, std::move(request)),
delegate_(delegate) {} delegate_(delegate) {}
......
...@@ -41,6 +41,7 @@ class AddSupervisionHandler ...@@ -41,6 +41,7 @@ class AddSupervisionHandler
AddSupervisionHandler( AddSupervisionHandler(
add_supervision::mojom::AddSupervisionHandlerRequest request, add_supervision::mojom::AddSupervisionHandlerRequest request,
content::WebUI* web_ui, content::WebUI* web_ui,
signin::IdentityManager* identity_manager,
Delegate* delegate); Delegate* delegate);
~AddSupervisionHandler() override; ~AddSupervisionHandler() override;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "content/public/test/test_web_ui.h" #include "content/public/test/test_web_ui.h"
namespace chromeos { namespace chromeos {
...@@ -49,10 +50,12 @@ class AddSupervisionMetricsRecorderTest : public InProcessBrowserTest { ...@@ -49,10 +50,12 @@ class AddSupervisionMetricsRecorderTest : public InProcessBrowserTest {
} }
void NotifySupervisionEnabled() { void NotifySupervisionEnabled() {
signin::IdentityTestEnvironment identity_test_env;
add_supervision::mojom::AddSupervisionHandlerRequest request; add_supervision::mojom::AddSupervisionHandlerRequest request;
AddSupervisionUI add_supervision_ui(&test_web_ui_); AddSupervisionUI add_supervision_ui(&test_web_ui_);
AddSupervisionHandler add_supervision_handler( AddSupervisionHandler add_supervision_handler(
std::move(request), &test_web_ui_, &add_supervision_ui); std::move(request), &test_web_ui_, identity_test_env.identity_manager(),
&add_supervision_ui);
add_supervision_handler.NotifySupervisionEnabled(); add_supervision_handler.NotifySupervisionEnabled();
} }
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/ui/views/chrome_web_dialog_view.h" #include "chrome/browser/ui/views/chrome_web_dialog_view.h"
#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler_utils.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler_utils.h"
#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder.h"
...@@ -56,22 +58,6 @@ const char kAddSupervisionDefaultURL[] = ...@@ -56,22 +58,6 @@ const char kAddSupervisionDefaultURL[] =
const char kAddSupervisionFlowType[] = "1"; const char kAddSupervisionFlowType[] = "1";
const char kAddSupervisionSwitch[] = "add-supervision-url"; const char kAddSupervisionSwitch[] = "add-supervision-url";
// Returns the URL of the Add Supervision flow from the command-line switch,
// or the default value if it's not defined.
GURL GetAddSupervisionURL() {
std::string url;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(kAddSupervisionSwitch)) {
url = command_line->GetSwitchValueASCII(kAddSupervisionSwitch);
} else {
url = kAddSupervisionDefaultURL;
}
const GURL result(url);
DCHECK(result.is_valid()) << "Invalid URL \"" << url << "\" for switch \""
<< kAddSupervisionSwitch << "\"";
return result;
}
} // namespace } // namespace
// AddSupervisionDialog implementations. // AddSupervisionDialog implementations.
...@@ -144,6 +130,9 @@ SystemWebDialogDelegate* AddSupervisionDialog::GetInstance() { ...@@ -144,6 +130,9 @@ SystemWebDialogDelegate* AddSupervisionDialog::GetInstance() {
// AddSupervisionUI implementations. // AddSupervisionUI implementations.
// static
signin::IdentityManager* AddSupervisionUI::test_identity_manager_ = nullptr;
AddSupervisionUI::AddSupervisionUI(content::WebUI* web_ui) AddSupervisionUI::AddSupervisionUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui) { : ui::MojoWebUIController(web_ui) {
// Register the Mojo API handler. // Register the Mojo API handler.
...@@ -151,17 +140,46 @@ AddSupervisionUI::AddSupervisionUI(content::WebUI* web_ui) ...@@ -151,17 +140,46 @@ AddSupervisionUI::AddSupervisionUI(content::WebUI* web_ui)
&AddSupervisionUI::BindAddSupervisionHandler, base::Unretained(this))); &AddSupervisionUI::BindAddSupervisionHandler, base::Unretained(this)));
// Set up the basic page framework. // Set up the basic page framework.
SetupResources(); SetUpResources();
}
AddSupervisionUI::~AddSupervisionUI() = default;
bool AddSupervisionUI::CloseDialog() {
bool showing_confirm_dialog = MaybeShowConfirmSignoutDialog();
if (!showing_confirm_dialog) {
// We aren't showing the confirm dialog, so close the AddSupervisionDialog.
AddSupervisionDialog::Close();
}
return !showing_confirm_dialog;
} }
void AddSupervisionUI::SetupResources() { // static
void AddSupervisionUI::SetUpForTest(signin::IdentityManager* identity_manager) {
test_identity_manager_ = identity_manager;
}
void AddSupervisionUI::BindAddSupervisionHandler(
add_supervision::mojom::AddSupervisionHandlerRequest request) {
signin::IdentityManager* identity_manager =
test_identity_manager_
? test_identity_manager_
: IdentityManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()));
mojo_api_handler_ = std::make_unique<AddSupervisionHandler>(
std::move(request), web_ui(), identity_manager, this);
}
void AddSupervisionUI::SetUpResources() {
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
std::unique_ptr<content::WebUIDataSource> source( std::unique_ptr<content::WebUIDataSource> source(
content::WebUIDataSource::Create(chrome::kChromeUIAddSupervisionHost)); content::WebUIDataSource::Create(chrome::kChromeUIAddSupervisionHost));
// Initialize supervision URL from the command-line arguments (if provided). // Initialize supervision URL from the command-line arguments (if provided).
supervision_url_ = GetAddSupervisionURL(); supervision_url_ = GetAddSupervisionURL();
DCHECK(supervision_url_.DomainIs("google.com")); if (!allow_non_google_url_for_tests_) {
DCHECK(supervision_url_.DomainIs("google.com"));
}
// Forward data to the WebUI. // Forward data to the WebUI.
source->AddResourcePath("post_message_api.js", source->AddResourcePath("post_message_api.js",
...@@ -201,21 +219,24 @@ void AddSupervisionUI::SetupResources() { ...@@ -201,21 +219,24 @@ void AddSupervisionUI::SetupResources() {
content::WebUIDataSource::Add(profile, source.release()); content::WebUIDataSource::Add(profile, source.release());
} }
AddSupervisionUI::~AddSupervisionUI() = default; // Returns the URL of the Add Supervision flow from the command-line switch,
// or the default value if it's not defined.
bool AddSupervisionUI::CloseDialog() { GURL AddSupervisionUI::GetAddSupervisionURL() {
bool showing_confirm_dialog = MaybeShowConfirmSignoutDialog(); std::string url;
if (!showing_confirm_dialog) { base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
// We aren't showing the confirm dialog, so close the AddSupervisionDialog. if (command_line->HasSwitch(kAddSupervisionSwitch)) {
AddSupervisionDialog::Close(); url = command_line->GetSwitchValueASCII(kAddSupervisionSwitch);
// The URL should only be set on the command line for testing purposes,
// which may include pointing to a non-google URL (i.e. http://localhost/).
// Therefore, we allow non-Google URLs in this instance.
allow_non_google_url_for_tests_ = true;
} else {
url = kAddSupervisionDefaultURL;
} }
return !showing_confirm_dialog; const GURL result(url);
} DCHECK(result.is_valid()) << "Invalid URL \"" << url << "\" for switch \""
<< kAddSupervisionSwitch << "\"";
void AddSupervisionUI::BindAddSupervisionHandler( return result;
add_supervision::mojom::AddSupervisionHandlerRequest request) {
mojo_api_handler_ = std::make_unique<AddSupervisionHandler>(
std::move(request), web_ui(), this);
} }
} // namespace chromeos } // namespace chromeos
...@@ -33,6 +33,8 @@ class AddSupervisionDialog : public SystemWebDialogDelegate { ...@@ -33,6 +33,8 @@ class AddSupervisionDialog : public SystemWebDialogDelegate {
// right. // right.
static void Close(); static void Close();
static SystemWebDialogDelegate* GetInstance();
// ui::WebDialogDelegate: // ui::WebDialogDelegate:
ui::ModalType GetDialogModalType() const override; ui::ModalType GetDialogModalType() const override;
void GetDialogSize(gfx::Size* size) const override; void GetDialogSize(gfx::Size* size) const override;
...@@ -50,8 +52,6 @@ class AddSupervisionDialog : public SystemWebDialogDelegate { ...@@ -50,8 +52,6 @@ class AddSupervisionDialog : public SystemWebDialogDelegate {
FRIEND_TEST_ALL_PREFIXES(AddSupervisionMetricsRecorderTimeTest, FRIEND_TEST_ALL_PREFIXES(AddSupervisionMetricsRecorderTimeTest,
UserTimingTest); UserTimingTest);
static SystemWebDialogDelegate* GetInstance();
DISALLOW_COPY_AND_ASSIGN(AddSupervisionDialog); DISALLOW_COPY_AND_ASSIGN(AddSupervisionDialog);
}; };
...@@ -65,16 +65,22 @@ class AddSupervisionUI : public ui::MojoWebUIController, ...@@ -65,16 +65,22 @@ class AddSupervisionUI : public ui::MojoWebUIController,
// AddSupervisionHandler::Delegate: // AddSupervisionHandler::Delegate:
bool CloseDialog() override; bool CloseDialog() override;
static void SetUpForTest(signin::IdentityManager* identity_manager);
private: private:
void BindAddSupervisionHandler( void BindAddSupervisionHandler(
add_supervision::mojom::AddSupervisionHandlerRequest request); add_supervision::mojom::AddSupervisionHandlerRequest request);
void SetupResources(); void SetUpResources();
GURL GetAddSupervisionURL();
std::unique_ptr<add_supervision::mojom::AddSupervisionHandler> std::unique_ptr<add_supervision::mojom::AddSupervisionHandler>
mojo_api_handler_; mojo_api_handler_;
GURL supervision_url_; GURL supervision_url_;
static signin::IdentityManager* test_identity_manager_;
bool allow_non_google_url_for_tests_ = false;
DISALLOW_COPY_AND_ASSIGN(AddSupervisionUI); DISALLOW_COPY_AND_ASSIGN(AddSupervisionUI);
}; };
......
// Copyright 2019 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 <string>
#include "base/macros.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder.h"
#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h"
#include "chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/network_connection_change_simulator.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos {
// NOTE: This test is flaky and therefore disabled under MSAN:
// https://crbug.com/1002560
#if !defined(MEMORY_SANITIZER)
namespace {
const char kGetAddSupervisionUIElementJS[] =
"document.querySelector('add-supervision-ui')";
}
// Base class for AddSupervision tests.
class AddSupervisionBrowserTest : public InProcessBrowserTest {
public:
AddSupervisionBrowserTest() {
scoped_feature_list_.InitWithFeatures(
{chromeos::features::kParentalControlsSettings}, {});
}
~AddSupervisionBrowserTest() override = default;
void SetUpOnMainThread() override {
// TODO(danan): See if this is possible to do this instead using
// FakeGaia.IssueOAuthToken().
identity_test_env_ = std::make_unique<signin::IdentityTestEnvironment>();
identity_test_env_->MakePrimaryAccountAvailable("example@gmail.com");
// This makes the identity manager return the string "access_token" for the
// access token.
identity_test_env_->SetAutomaticIssueOfAccessTokens(true);
AddSupervisionUI::SetUpForTest(identity_test_env_->identity_manager());
// Set start_time_ so that the DCHECK(!start_time_.is_null()) in
// AddSupervisionMetricsRecorder::RecordUserTime() doesn't throw.
AddSupervisionMetricsRecorder::GetInstance()
->RecordAddSupervisionEnrollment(
AddSupervisionMetricsRecorder::EnrollmentState::kInitiated);
}
chromeos::AddSupervisionUI* GetAddSupervisionUI() {
return static_cast<chromeos::AddSupervisionUI*>(
contents()->GetWebUI()->GetController());
}
content::WebContents* contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
GURL settings_webui_url() { return GURL(chrome::kChromeUISettingsURL); }
GURL add_supervision_webui_url() {
return GURL(chrome::kChromeUIAddSupervisionURL);
}
bool IsElementVisible(const std::string& element_selector) {
bool found;
bool hidden;
std::string script = std::string("domAutomationController.send(") +
element_selector + ".hidden);";
LOG(ERROR) << "Script: " << script;
found = content::ExecuteScriptAndExtractBool(contents(), script, &hidden);
return found && !hidden;
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<signin::IdentityTestEnvironment> identity_test_env_;
DISALLOW_COPY_AND_ASSIGN(AddSupervisionBrowserTest);
};
IN_PROC_BROWSER_TEST_F(AddSupervisionBrowserTest, URLParameters) {
// Open the Add Supervision URL.
ui_test_utils::NavigateToURL(browser(), add_supervision_webui_url());
content::WaitForLoadStop(contents());
// Get the URL from the embedded webview.
std::string webview_url;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
contents(),
std::string("domAutomationController.send(") +
std::string(kGetAddSupervisionUIElementJS) +
".shadowRoot.querySelector('#webview').getAttribute('src')" +
std::string(");"),
&webview_url));
GURL webview_gurl(webview_url);
ASSERT_TRUE(webview_gurl.has_query());
// Split the query string into a map of keys to values.
std::string query_str = webview_gurl.query();
url::Component query(0, query_str.length());
url::Component key;
url::Component value;
std::map<std::string, std::string> query_parts;
while (url::ExtractQueryKeyValue(query_str.c_str(), &query, &key, &value)) {
query_parts[query_str.substr(key.begin, key.len)] =
query_str.substr(value.begin, value.len);
}
// Validate the query parameters.
ASSERT_EQ(query_parts.at("flow_type"), "1");
ASSERT_EQ(query_parts.at("platform_version"),
base::SysInfo::OperatingSystemVersion());
ASSERT_EQ(query_parts.at("access_token"), "access_token");
ASSERT_EQ(query_parts.at("hl"), "en-US");
}
IN_PROC_BROWSER_TEST_F(AddSupervisionBrowserTest, ShowOfflineScreen) {
// Open the Add Supervision URL.
ui_test_utils::NavigateToURL(browser(), add_supervision_webui_url());
content::WaitForLoadStop(contents());
// Webview div should be initially visible.
ASSERT_TRUE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) +
std::string(".webviewDiv")));
// Simulate going offline.
ASSERT_TRUE(content::ExecuteScript(
contents(), "window.dispatchEvent(new CustomEvent('offline'));"));
// Ensure the offline content view is shown.
ASSERT_TRUE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) +
std::string(".offlineContentDiv")));
// Ensure the online webview content content is hidden.
ASSERT_FALSE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) +
std::string(".webviewDiv")));
// Simulate going online.
ASSERT_TRUE(content::ExecuteScript(
contents(), "window.dispatchEvent(new CustomEvent('online'));"));
// Offline div should be hidden.
ASSERT_FALSE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) +
std::string(".offlineContentDiv")));
// Webview div should be shown.
ASSERT_TRUE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) +
std::string(".webviewDiv")));
}
IN_PROC_BROWSER_TEST_F(AddSupervisionBrowserTest, ShowConfirmSignoutDialog) {
// Open the Add Supervision URL.
ui_test_utils::NavigateToURL(browser(), add_supervision_webui_url());
content::WaitForLoadStop(contents());
// Request that the dialog close before supervision has been enabled.
ASSERT_TRUE(content::ExecuteScript(
contents(), std::string(kGetAddSupervisionUIElementJS) +
std::string(".server.requestClose()")));
// Confirm that the signout dialog isn't showing
ASSERT_FALSE(ConfirmSignoutDialog::IsShowing());
// Simulate supervision being enabled.
ASSERT_TRUE(content::ExecuteScript(
contents(), std::string(kGetAddSupervisionUIElementJS) +
std::string(".server.notifySupervisionEnabled()")));
// Request that the dialog is closed again.
ASSERT_TRUE(content::ExecuteScript(
contents(), std::string(kGetAddSupervisionUIElementJS) +
std::string(".server.requestClose()")));
// Confirm that the dialog is showing.
ASSERT_TRUE(ConfirmSignoutDialog::IsShowing());
}
#endif // !defined(MEMORY_SANITIZER)
} // namespace chromeos
...@@ -44,7 +44,9 @@ ConfirmSignoutDialog::ConfirmSignoutDialog() { ...@@ -44,7 +44,9 @@ ConfirmSignoutDialog::ConfirmSignoutDialog() {
AddChildView(body); AddChildView(body);
} }
ConfirmSignoutDialog::~ConfirmSignoutDialog() = default; ConfirmSignoutDialog::~ConfirmSignoutDialog() {
ConfirmSignoutDialog::current_instance_ = nullptr;
}
ui::ModalType ConfirmSignoutDialog::GetModalType() const { ui::ModalType ConfirmSignoutDialog::GetModalType() const {
return ui::ModalType::MODAL_TYPE_SYSTEM; return ui::ModalType::MODAL_TYPE_SYSTEM;
...@@ -74,13 +76,22 @@ base::string16 ConfirmSignoutDialog::GetDialogButtonLabel( ...@@ -74,13 +76,22 @@ base::string16 ConfirmSignoutDialog::GetDialogButtonLabel(
IDS_ADD_SUPERVISION_EXIT_DIALOG_CANCEL_BUTTON_LABEL); IDS_ADD_SUPERVISION_EXIT_DIALOG_CANCEL_BUTTON_LABEL);
} }
// static
views::Widget* ConfirmSignoutDialog::current_instance_ = nullptr;
// static // static
void ConfirmSignoutDialog::Show() { void ConfirmSignoutDialog::Show() {
// Ownership of the ConfirmSignoutDialog is passed to the views system. // Ownership of the ConfirmSignoutDialog is passed to the views system.
// Dialog is system-modal, so no parent window is needed. // Dialog is system-modal, so no parent window is needed.
constrained_window::CreateBrowserModalDialogViews(new ConfirmSignoutDialog(), ConfirmSignoutDialog::current_instance_ =
nullptr /* parent window */) constrained_window::CreateBrowserModalDialogViews(
->Show(); new ConfirmSignoutDialog(), nullptr /* parent window */);
current_instance_->Show();
}
// static
bool ConfirmSignoutDialog::IsShowing() {
return ConfirmSignoutDialog::current_instance_ != nullptr;
} }
} // namespace chromeos } // namespace chromeos
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
namespace views {
class Widget;
}
namespace chromeos { namespace chromeos {
// Dialog shown when the user tries to close the flow when account has already // Dialog shown when the user tries to close the flow when account has already
...@@ -28,9 +32,11 @@ class ConfirmSignoutDialog : public views::DialogDelegateView { ...@@ -28,9 +32,11 @@ class ConfirmSignoutDialog : public views::DialogDelegateView {
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
static void Show(); static void Show();
static bool IsShowing();
private: private:
ConfirmSignoutDialog(); ConfirmSignoutDialog();
static views::Widget* current_instance_;
DISALLOW_COPY_AND_ASSIGN(ConfirmSignoutDialog); DISALLOW_COPY_AND_ASSIGN(ConfirmSignoutDialog);
}; };
......
...@@ -2284,6 +2284,7 @@ if (!is_android) { ...@@ -2284,6 +2284,7 @@ if (!is_android) {
"../browser/ui/views/frame/top_controls_slide_controller_chromeos_browsertest.cc", "../browser/ui/views/frame/top_controls_slide_controller_chromeos_browsertest.cc",
"../browser/ui/views/plugin_vm/plugin_vm_launcher_view_browsertest.cc", "../browser/ui/views/plugin_vm/plugin_vm_launcher_view_browsertest.cc",
"../browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder_browsertest.cc", "../browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder_browsertest.cc",
"../browser/ui/webui/chromeos/add_supervision/add_supervision_ui_browsertest.cc",
"../browser/ui/webui/chromeos/login/discover/discover_browser_test.cc", "../browser/ui/webui/chromeos/login/discover/discover_browser_test.cc",
"../browser/ui/webui/chromeos/login/discover/discover_browser_test.h", "../browser/ui/webui/chromeos/login/discover/discover_browser_test.h",
"../browser/ui/webui/chromeos/login/discover/modules/discover_module_launch_help_app_test.cc", "../browser/ui/webui/chromeos/login/discover/modules/discover_module_launch_help_app_test.cc",
......
...@@ -652,6 +652,8 @@ cr.define('settings_people_page', function() { ...@@ -652,6 +652,8 @@ cr.define('settings_people_page', function() {
showOSSettings: false, showOSSettings: false,
// Simulate ChromeOSAccountManager (Google Accounts support). // Simulate ChromeOSAccountManager (Google Accounts support).
isAccountManagerEnabled: true, isAccountManagerEnabled: true,
// Simulate parental controls.
showParentalControls: true,
}); });
}); });
...@@ -709,6 +711,160 @@ cr.define('settings_people_page', function() { ...@@ -709,6 +711,160 @@ cr.define('settings_people_page', function() {
profileIcon.click(); profileIcon.click();
assertEquals(oldRoute, settings.getCurrentRoute()); assertEquals(oldRoute, settings.getCurrentRoute());
}); });
test('parental controls page is shown when enabled', () => {
// Setup button is shown and enabled.
const parentalControlsItem =
assert(peoplePage.$$('settings-parental-controls-page'));
});
});
/** @implements {parental_controls.ParentalControlsBrowserProxy} */
class TestParentalControlsBrowserProxy extends TestBrowserProxy {
constructor() {
super([
'showAddSupervisionDialog',
'launchFamilyLinkSettings',
]);
}
/** @override */
launchFamilyLinkSettings() {
this.methodCalled('launchFamilyLinkSettings');
}
/** @override */
showAddSupervisionDialog() {
this.methodCalled('showAddSupervisionDialog');
}
}
suite('Chrome OS parental controls page setup item tests', function() {
/** @type {ParentalControlsPage} */
let parentalControlsPage = null;
/** @type {TestParentalControlsBrowserProxy} */
let parentalControlsBrowserProxy = null;
suiteSetup(function() {
loadTimeData.overrideValues({
// Simulate parental controls.
showParentalControls: true,
});
});
setup(function() {
parentalControlsBrowserProxy = new TestParentalControlsBrowserProxy();
parental_controls.BrowserProxyImpl.instance_ =
parentalControlsBrowserProxy;
PolymerTest.clearBody();
parentalControlsPage =
document.createElement('settings-parental-controls-page');
parentalControlsPage.pageVisibility = settings.pageVisibility;
document.body.appendChild(parentalControlsPage);
Polymer.dom.flush();
});
teardown(function() {
parentalControlsPage.remove();
});
test('parental controls page enabled when online', () => {
// Setup button is shown and enabled.
const setupButton = assert(
parentalControlsPage.$$('#parental-controls-item cr-button'));
setupButton.click();
// Ensure that the request to launch the add supervision flow went
// through.
assertEquals(
parentalControlsBrowserProxy.getCallCount(
'showAddSupervisionDialog'),
1);
});
test('parental controls page disabled when offline', () => {
// Simulate going offline
window.dispatchEvent(new CustomEvent('offline'));
// Setup button is shown but disabled.
const setupButton = assert(
parentalControlsPage.$$('#parental-controls-item cr-button'));
assertTrue(setupButton.disabled);
setupButton.click();
// Ensure that the request to launch the add supervision flow does not
// go through.
assertEquals(
parentalControlsBrowserProxy.getCallCount(
'showAddSupervisionDialog'),
0);
});
test(
'parental controls page re-enabled when it comes back online', () => {
// Simulate going offline
window.dispatchEvent(new CustomEvent('offline'));
// Setup button is shown but disabled.
const setupButton = assert(
parentalControlsPage.$$('#parental-controls-item cr-button'));
assertTrue(setupButton.disabled);
// Come back online.
window.dispatchEvent(new CustomEvent('online'));
// Setup button is shown and re-enabled.
assertFalse(setupButton.disabled);
});
});
suite('Chrome OS parental controls page child account tests', function() {
/** @type {ParentalControlsPage} */
let parentalControlsPage = null;
/** @type {TestParentalControlsBrowserProxy} */
let parentalControlsBrowserProxy = null;
suiteSetup(function() {
loadTimeData.overrideValues({
// Simulate parental controls.
showParentalControls: true,
// Simulate child account.
isChild: true,
});
});
setup(async function() {
parentalControlsBrowserProxy = new TestParentalControlsBrowserProxy();
parental_controls.BrowserProxyImpl.instance_ =
parentalControlsBrowserProxy;
PolymerTest.clearBody();
parentalControlsPage =
document.createElement('settings-parental-controls-page');
parentalControlsPage.pageVisibility = settings.pageVisibility;
document.body.appendChild(parentalControlsPage);
Polymer.dom.flush();
});
teardown(function() {
parentalControlsPage.remove();
});
test('parental controls page child view shown to child account', () => {
// Get the link row.
const linkRow = assert(
parentalControlsPage.$$('#parental-controls-item cr-link-row'));
linkRow.click();
// Ensure that the request to launch FLH went through.
assertEquals(
parentalControlsBrowserProxy.getCallCount(
'launchFamilyLinkSettings'),
1);
});
}); });
} }
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment