Commit 46b97c78 authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Plumb "Done" button in profile customization bubble

Bug: 1130945
Change-Id: I2c4ff4b016b8ac936630686ebd8ef03f238c6e9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2445779Reviewed-by: default avatarMonica Basta <msalama@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813690}
parent 16da4295
......@@ -339,6 +339,7 @@
<include name="IDR_PROFILE_BROWSER_PROXY_JS" file="resources\user_manager\profile_browser_proxy.js" type="BINDATA" />
<include name="IDR_PROFILE_CUSTOMIZATION_HTML" file="resources\signin\profile_customization\profile_customization.html" type="BINDATA" />
<include name="IDR_PROFILE_CUSTOMIZATION_APP_JS" file="${root_gen_dir}\chrome\browser\resources\signin\profile_customization\profile_customization_app.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_PROFILE_CUSTOMIZATION_BROWSER_PROXY_JS" file="resources\signin\profile_customization\profile_customization_browser_proxy.js" type="BINDATA" />
<include name="IDR_USER_MANAGER_HTML" file="resources\user_manager\user_manager.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_USER_MANAGER_JS" file="resources\user_manager\user_manager.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_USER_MANAGER_PAGES_HTML" file="resources\user_manager\user_manager_pages.html" type="BINDATA" />
......
......@@ -7,15 +7,24 @@ import("//tools/polymer/html_to_js.gni")
js_type_check("closure_compile") {
is_polymer3 = true
deps = [ ":profile_customization_app" ]
deps = [
":profile_customization_app",
":profile_customization_browser_proxy",
]
}
js_library("profile_customization_app") {
deps = [
":profile_customization_browser_proxy",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
]
}
js_library("profile_customization_browser_proxy") {
deps = [ "//ui/webui/resources/js:cr.m" ]
externs_list = [ "$externs_path/chrome_send.js" ]
}
html_to_js("web_components") {
js_files = [ "profile_customization_app.js" ]
}
<div>$i18n{profileCustomizationPickThemeTitle}</div>
<cr-button on-click="onDone_" autofocus>
<cr-button id="doneButton" on-click="onDoneCustomizationClicked_">
$i18n{profileCustomizationDoneLabel}
</cr-button>
......@@ -7,14 +7,24 @@ import './strings.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {ProfileCustomizationBrowserProxy, ProfileCustomizationBrowserProxyImpl} from './profile_customization_browser_proxy.js';
Polymer({
is: 'profile-customization-app',
_template: html`{__html_template__}`,
/** @private {?ProfileCustomizationBrowserProxy} */
profileCustomizationBrowserProxy_: null,
/** @override */
ready() {
this.profileCustomizationBrowserProxy_ =
ProfileCustomizationBrowserProxyImpl.getInstance();
},
/** @private */
onDone_() {
// TODO: call native to close the bubble
onDoneCustomizationClicked_() {
this.profileCustomizationBrowserProxy_.done();
},
});
// Copyright 2020 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.
/**
* @fileoverview A helper object used by the profilecustomization bubble to
* interact with the browser.
*/
import {addSingletonGetter, sendWithPromise} from 'chrome://resources/js/cr.m.js';
/** @interface */
export class ProfileCustomizationBrowserProxy {
/** Called when the user clicks the done button. */
done() {}
}
/** @implements {ProfileCustomizationBrowserProxy} */
export class ProfileCustomizationBrowserProxyImpl {
/** @override */
done() {
chrome.send('done');
}
}
addSingletonGetter(ProfileCustomizationBrowserProxyImpl);
......@@ -11,6 +11,7 @@
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/profiles/avatar_toolbar_button.h"
#include "chrome/browser/ui/webui/signin/profile_customization_ui.h"
#include "chrome/common/webui_url_constants.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
......@@ -42,12 +43,22 @@ ProfileCustomizationBubbleView::ProfileCustomizationBubbleView(
views::View* anchor_view)
: views::BubbleDialogDelegateView(anchor_view,
views::BubbleBorder::TOP_RIGHT) {
set_close_on_deactivate(false);
// Create the web view in the native bubble.
std::unique_ptr<views::WebView> web_view =
std::make_unique<views::WebView>(profile);
web_view->LoadInitialURL(GURL(chrome::kChromeUIProfileCustomizationURL));
web_view->SetPreferredSize(
gfx::Size(kCustomizationBubbleWidth, kCustomizationBubbleHeight));
ProfileCustomizationUI* web_ui = web_view->GetWebContents()
->GetWebUI()
->GetController()
->GetAs<ProfileCustomizationUI>();
DCHECK(web_ui);
web_ui->Initialize(
base::BindOnce(&ProfileCustomizationBubbleView::OnDoneButtonClicked,
// Unretained is fine because this owns the web view.
base::Unretained(this)));
AddChildView(std::move(web_view));
set_margins(gfx::Insets());
......@@ -55,6 +66,11 @@ ProfileCustomizationBubbleView::ProfileCustomizationBubbleView(
SetLayoutManager(std::make_unique<views::FillLayout>());
}
void ProfileCustomizationBubbleView::OnDoneButtonClicked() {
GetWidget()->CloseWithReason(
views::Widget::ClosedReason::kCloseButtonClicked);
}
void DiceWebSigninInterceptorDelegate::ShowProfileCustomizationBubbleInternal(
Browser* browser) {
DCHECK(browser);
......
......@@ -27,6 +27,9 @@ class ProfileCustomizationBubbleView : public views::BubbleDialogDelegateView {
private:
ProfileCustomizationBubbleView(Profile* profile, views::View* anchor_view);
// Called when the "Done" button is clicked in the inner WebUI.
void OnDoneButtonClicked();
};
#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CUSTOMIZATION_BUBBLE_VIEW_H_
......@@ -4,11 +4,16 @@
#include "chrome/browser/ui/webui/signin/profile_customization_handler.h"
#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
ProfileCustomizationHandler::ProfileCustomizationHandler() = default;
ProfileCustomizationHandler::ProfileCustomizationHandler(
base::OnceClosure done_closure)
: done_closure_(std::move(done_closure)) {}
ProfileCustomizationHandler::~ProfileCustomizationHandler() = default;
......@@ -19,5 +24,6 @@ void ProfileCustomizationHandler::RegisterMessages() {
}
void ProfileCustomizationHandler::HandleDone(const base::ListValue* args) {
// TODO: close the bubble
if (done_closure_)
std::move(done_closure_).Run();
}
......@@ -7,6 +7,8 @@
#include "content/public/browser/web_ui_message_handler.h"
#include "base/callback.h"
namespace base {
class ListValue;
}
......@@ -14,7 +16,7 @@ class ListValue;
// WebUI message handler for the profile customization bubble.
class ProfileCustomizationHandler : public content::WebUIMessageHandler {
public:
ProfileCustomizationHandler();
explicit ProfileCustomizationHandler(base::OnceClosure done_closure);
~ProfileCustomizationHandler() override;
ProfileCustomizationHandler(const ProfileCustomizationHandler&) = delete;
......@@ -26,6 +28,9 @@ class ProfileCustomizationHandler : public content::WebUIMessageHandler {
private:
void HandleDone(const base::ListValue* args);
// Called when the "Done" button has been pressed.
base::OnceClosure done_closure_;
};
#endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_PROFILE_CUSTOMIZATION_HANDLER_H_
......@@ -23,6 +23,8 @@ ProfileCustomizationUI::ProfileCustomizationUI(content::WebUI* web_ui)
source->SetDefaultResource(IDR_PROFILE_CUSTOMIZATION_HTML);
source->AddResourcePath("profile_customization_app.js",
IDR_PROFILE_CUSTOMIZATION_APP_JS);
source->AddResourcePath("profile_customization_browser_proxy.js",
IDR_PROFILE_CUSTOMIZATION_BROWSER_PROXY_JS);
// Localized strings.
source->UseStringsJs();
......@@ -44,8 +46,13 @@ ProfileCustomizationUI::ProfileCustomizationUI(content::WebUI* web_ui)
source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER);
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
web_ui->AddMessageHandler(std::make_unique<ProfileCustomizationHandler>());
}
ProfileCustomizationUI::~ProfileCustomizationUI() = default;
void ProfileCustomizationUI::Initialize(base::OnceClosure done_closure) {
web_ui()->AddMessageHandler(
std::make_unique<ProfileCustomizationHandler>(std::move(done_closure)));
}
WEB_UI_CONTROLLER_TYPE_IMPL(ProfileCustomizationUI)
......@@ -7,6 +7,8 @@
#include "content/public/browser/web_ui_controller.h"
#include "base/callback.h"
namespace content {
class WebUI;
}
......@@ -18,6 +20,12 @@ class ProfileCustomizationUI : public content::WebUIController {
ProfileCustomizationUI(const ProfileCustomizationUI&) = delete;
ProfileCustomizationUI& operator=(const ProfileCustomizationUI&) = delete;
// Initializes the ProfileCustomizationUI.
void Initialize(base::OnceClosure done_closure);
private:
WEB_UI_CONTROLLER_TYPE_DECL();
};
#endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_PROFILE_CUSTOMIZATION_UI_H_
......@@ -8,6 +8,7 @@ js_type_check("closure_compile") {
is_polymer3 = true
closure_flags = default_closure_args + [
"browser_resolver_prefix_replacements=\"chrome://signin-dice-web-intercept/=../../chrome/browser/resources/signin/dice_web_signin_intercept/\"",
"browser_resolver_prefix_replacements=\"chrome://profile-customization/=../../chrome/browser/resources/signin/profile_customization/\"",
"browser_resolver_prefix_replacements=\"chrome://profile-picker/=../../chrome/browser/resources/signin/profile_picker/\"",
"js_module_root=../../chrome/test/data/webui/",
"js_module_root=./gen/chrome/test/data/webui/",
......@@ -15,9 +16,11 @@ js_type_check("closure_compile") {
deps = [
":dice_web_signin_intercept_test",
":profile_creation_flow_test",
":profile_customization_test",
":profile_picker_app_test",
":test_dice_web_signin_intercept_browser_proxy",
":test_manage_profiles_browser_proxy",
":test_profile_customization_browser_proxy",
]
}
......@@ -38,6 +41,17 @@ js_library("profile_creation_flow_test") {
"..:test_util.m",
"//chrome/browser/resources/signin/profile_picker:lazy_load",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("profile_customization_test") {
deps = [
":test_profile_customization_browser_proxy",
"..:chai_assert",
"..:test_util.m",
"//chrome/browser/resources/signin/profile_customization:profile_customization_app",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("profile_picker_app_test") {
......@@ -47,6 +61,7 @@ js_library("profile_picker_app_test") {
"..:test_util.m",
"//chrome/browser/resources/signin/profile_picker:profile_picker",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("test_dice_web_signin_intercept_browser_proxy") {
......@@ -56,6 +71,13 @@ js_library("test_dice_web_signin_intercept_browser_proxy") {
]
}
js_library("test_profile_customization_browser_proxy") {
deps = [
"..:test_browser_proxy.m",
"//chrome/browser/resources/signin/profile_customization:profile_customization_browser_proxy",
]
}
js_library("test_manage_profiles_browser_proxy") {
deps = [
"..:test_browser_proxy.m",
......
// Copyright 2020 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.
import 'chrome://profile-customization/profile_customization_app.js';
import {ProfileCustomizationBrowserProxyImpl} from 'chrome://profile-customization/profile_customization_browser_proxy.js';
import {assertTrue} from '../chai_assert.js';
import {isChildVisible} from '../test_util.m.js';
import {TestProfileCustomizationBrowserProxy} from './test_profile_customization_browser_proxy.js';
suite('ProfileCustomizationTest', function() {
/** @type {!ProfileCustomizationAppElement} */
let app;
/** @type {!TestProfileCustomizationBrowserProxy} */
let browserProxy;
setup(function() {
browserProxy = new TestProfileCustomizationBrowserProxy();
ProfileCustomizationBrowserProxyImpl.instance_ = browserProxy;
document.body.innerHTML = '';
app = /** @type {!ProfileCustomizationAppElement} */ (
document.createElement('profile-customization-app'));
document.body.append(app);
});
test('ClickDone', function() {
assertTrue(isChildVisible(app, '#doneButton'));
app.$$('#doneButton').click();
return browserProxy.whenCalled('done');
});
});
......@@ -132,3 +132,29 @@ var ProfilePickerAppTest = class extends SigninBrowserTest {
TEST_F('ProfilePickerAppTest', 'ButtonsImplementation', function() {
mocha.run();
});
/**
* Test fixture for
* chrome/browser/resources/signin/profile_customization/profile_customization_app.html.
* This has to be declared as a variable for TEST_F to find it correctly.
*/
// eslint-disable-next-line no-var
var ProfileCustomizationTest = class extends SigninBrowserTest {
/** @override */
get browsePreload() {
return 'chrome://profile-customization/test_loader.html?module=signin/profile_customization_test.js';
}
/** @override */
get featureList() {
return {
enabled: [
'features::kProfilesUIRevamp',
]
};
}
};
TEST_F('ProfileCustomizationTest', 'Bubble', function() {
mocha.run();
});
// Copyright 2020 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.
import {ProfileCustomizationBrowserProxy} from 'chrome://profile-customization/profile_customization_browser_proxy.js';
import {TestBrowserProxy} from '../test_browser_proxy.m.js';
/** @implements {ProfileCustomizationBrowserProxy} */
export class TestProfileCustomizationBrowserProxy extends TestBrowserProxy {
constructor() {
super(['done']);
}
/** @override */
done() {
this.methodCalled('done');
}
}
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