summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/resources/settings/people_page/easy_unlock_browser_proxy.js37
-rw-r--r--chrome/browser/resources/settings/people_page/people_page.js2
-rw-r--r--chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc38
-rw-r--r--chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.h10
-rw-r--r--chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler_unittest.cc71
-rw-r--r--chrome/test/data/webui/settings/easy_unlock_browsertest_chromeos.js8
6 files changed, 113 insertions, 53 deletions
diff --git a/chrome/browser/resources/settings/people_page/easy_unlock_browser_proxy.js b/chrome/browser/resources/settings/people_page/easy_unlock_browser_proxy.js
index d46ec7e..72f0a9b 100644
--- a/chrome/browser/resources/settings/people_page/easy_unlock_browser_proxy.js
+++ b/chrome/browser/resources/settings/people_page/easy_unlock_browser_proxy.js
@@ -22,7 +22,23 @@ cr.define('settings', function() {
/**
* Starts the Easy Unlock setup flow.
*/
- launchSetup: function() {}
+ startTurnOnFlow: function() {},
+
+ /**
+ * Returns the Easy Unlock turn off flow status.
+ * @return {!Promise<string>}
+ */
+ getTurnOffFlowStatus: function() {},
+
+ /**
+ * Begins the Easy Unlock turn off flow.
+ */
+ startTurnOffFlow: function() {},
+
+ /**
+ * Cancels any in-progress Easy Unlock turn-off flows.
+ */
+ cancelTurnOffFlow: function() {},
};
/**
@@ -41,8 +57,23 @@ cr.define('settings', function() {
},
/** @override */
- launchSetup: function() {
- chrome.send('easyUnlockLaunchSetup');
+ startTurnOnFlow: function() {
+ chrome.send('easyUnlockStartTurnOnFlow');
+ },
+
+ /** @override */
+ getTurnOffFlowStatus: function() {
+ return cr.sendWithPromise('easyUnlockGetTurnOffFlowStatus');
+ },
+
+ /** @override */
+ startTurnOffFlow: function() {
+ chrome.send('easyUnlockStartTurnOffFlow');
+ },
+
+ /** @override */
+ cancelTurnOffFlow: function() {
+ chrome.send('easyUnlockCancelTurnOffFlow');
},
};
diff --git a/chrome/browser/resources/settings/people_page/people_page.js b/chrome/browser/resources/settings/people_page/people_page.js
index 19d109a..6963a2f 100644
--- a/chrome/browser/resources/settings/people_page/people_page.js
+++ b/chrome/browser/resources/settings/people_page/people_page.js
@@ -196,7 +196,7 @@ Polymer({
<if expr="chromeos">
/** @private */
onEasyUnlockSetupTap_: function() {
- this.browserProxy_.launchSetup();
+ this.browserProxy_.startTurnOnFlow();
},
/** @private */
diff --git a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc
index ce26f05..4245c3b 100644
--- a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc
+++ b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc
@@ -56,20 +56,20 @@ void EasyUnlockSettingsHandler::RegisterMessages() {
base::Bind(&EasyUnlockSettingsHandler::HandleGetEnabledStatus,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "easyUnlockLaunchSetup",
- base::Bind(&EasyUnlockSettingsHandler::HandleLaunchSetup,
+ "easyUnlockStartTurnOnFlow",
+ base::Bind(&EasyUnlockSettingsHandler::HandleStartTurnOnFlow,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"easyUnlockGetTurnOffFlowStatus",
base::Bind(&EasyUnlockSettingsHandler::HandleGetTurnOffFlowStatus,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "easyUnlockRequestTurnOff",
- base::Bind(&EasyUnlockSettingsHandler::HandleRequestTurnOff,
+ "easyUnlockStartTurnOffFlow",
+ base::Bind(&EasyUnlockSettingsHandler::HandleStartTurnOffFlow,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "easyUnlockTurnOffOverlayDismissed",
- base::Bind(&EasyUnlockSettingsHandler::HandlePageDismissed,
+ "easyUnlockCancelTurnOffFlow",
+ base::Bind(&EasyUnlockSettingsHandler::HandleCancelTurnOffFlow,
base::Unretained(this)));
}
@@ -86,7 +86,10 @@ void EasyUnlockSettingsHandler::RenderViewReused() {
}
void EasyUnlockSettingsHandler::OnTurnOffOperationStatusChanged() {
- SendTurnOffOperationStatus();
+ web_ui()->CallJavascriptFunction(
+ "cr.webUIListenerCallback",
+ base::StringValue("easy-unlock-turn-off-flow-status"),
+ base::StringValue(GetTurnOffFlowStatus()));
}
void EasyUnlockSettingsHandler::SendEnabledStatus() {
@@ -96,12 +99,12 @@ void EasyUnlockSettingsHandler::SendEnabledStatus() {
base::FundamentalValue(EasyUnlockService::Get(profile_)->IsEnabled()));
}
-void EasyUnlockSettingsHandler::SendTurnOffOperationStatus() {
+std::string EasyUnlockSettingsHandler::GetTurnOffFlowStatus() {
EasyUnlockService::TurnOffFlowStatus status =
EasyUnlockService::Get(profile_)->GetTurnOffFlowStatus();
// Translate status into JS UI state string. Note the translated string
- // should match UIState defined in easy_unlock_turn_off_overlay.js.
+ // should match UIState defined in easy_unlock_turn_off_dialog.js.
std::string status_string;
switch (status) {
case EasyUnlockService::IDLE:
@@ -119,10 +122,7 @@ void EasyUnlockSettingsHandler::SendTurnOffOperationStatus() {
break;
}
- web_ui()->CallJavascriptFunction(
- "cr.webUIListenerCallback",
- base::StringValue("easy-unlock-turn-off-flow-status"),
- base::StringValue(status_string));
+ return status_string;
}
void EasyUnlockSettingsHandler::HandleGetEnabledStatus(
@@ -148,22 +148,26 @@ void EasyUnlockSettingsHandler::HandleGetEnabledStatus(
base::FundamentalValue(EasyUnlockService::Get(profile_)->IsEnabled()));
}
-void EasyUnlockSettingsHandler::HandleLaunchSetup(
+void EasyUnlockSettingsHandler::HandleStartTurnOnFlow(
const base::ListValue* args) {
EasyUnlockService::Get(profile_)->LaunchSetup();
}
void EasyUnlockSettingsHandler::HandleGetTurnOffFlowStatus(
const base::ListValue* args) {
- SendTurnOffOperationStatus();
+ CHECK_EQ(1U, args->GetSize());
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+ ResolveJavascriptCallback(*callback_id,
+ base::StringValue(GetTurnOffFlowStatus()));
}
-void EasyUnlockSettingsHandler::HandleRequestTurnOff(
+void EasyUnlockSettingsHandler::HandleStartTurnOffFlow(
const base::ListValue* args) {
EasyUnlockService::Get(profile_)->RunTurnOffFlow();
}
-void EasyUnlockSettingsHandler::HandlePageDismissed(
+void EasyUnlockSettingsHandler::HandleCancelTurnOffFlow(
const base::ListValue* args) {
EasyUnlockService::Get(profile_)->ResetTurnOffFlow();
}
diff --git a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.h b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.h
index 992461e..e3f5e82 100644
--- a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.h
+++ b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.h
@@ -41,17 +41,17 @@ class EasyUnlockSettingsHandler : public ::settings::SettingsPageUIHandler,
private:
FRIEND_TEST_ALL_PREFIXES(EasyUnlockSettingsHandlerTest, EnabledStatus);
- FRIEND_TEST_ALL_PREFIXES(EasyUnlockSettingsHandlerTest, TurnOffStatus);
+ FRIEND_TEST_ALL_PREFIXES(EasyUnlockSettingsHandlerTest, TurnOffFlowStatus);
void SendEnabledStatus();
- void SendTurnOffOperationStatus();
+ std::string GetTurnOffFlowStatus();
// JS callbacks.
void HandleGetEnabledStatus(const base::ListValue* args);
- void HandleLaunchSetup(const base::ListValue* args);
+ void HandleStartTurnOnFlow(const base::ListValue* args);
void HandleGetTurnOffFlowStatus(const base::ListValue* args);
- void HandleRequestTurnOff(const base::ListValue* args);
- void HandlePageDismissed(const base::ListValue* args);
+ void HandleStartTurnOffFlow(const base::ListValue* args);
+ void HandleCancelTurnOffFlow(const base::ListValue* args);
Profile* const profile_;
diff --git a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler_unittest.cc b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler_unittest.cc
index 47f2885..9b825b0 100644
--- a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler_unittest.cc
+++ b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler_unittest.cc
@@ -46,7 +46,7 @@ class FakeEasyUnlockService : public EasyUnlockService {
NotifyTurnOffOperationStatusChanged();
}
- void SetTurnOffFailForTest() {
+ void SetTurnOffFlowFailForTest() {
turn_off_status_ = FAIL;
NotifyTurnOffOperationStatusChanged();
}
@@ -134,8 +134,9 @@ class EasyUnlockSettingsHandlerTest : public testing::Test {
EXPECT_EQ(expected_status, status);
}
- void VerifyTurnOffStatusCallback(size_t expected_total_calls,
- const std::string& expected_status) {
+ void VerifyTurnOffFlowStatusWebUIListenerCallback(
+ size_t expected_total_calls,
+ const std::string& expected_status) {
std::string event;
std::string status;
@@ -150,6 +151,24 @@ class EasyUnlockSettingsHandlerTest : public testing::Test {
EXPECT_EQ(expected_status, status);
}
+ void VerifyTurnOffFlowStatusWebUIResponse(
+ size_t expected_total_calls,
+ const std::string& expected_callback_id,
+ const std::string& expected_status) {
+ EXPECT_EQ(expected_total_calls, web_ui()->call_data().size());
+
+ const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
+ EXPECT_EQ("cr.webUIResponse", data.function_name());
+
+ std::string callback_id;
+ ASSERT_TRUE(data.arg1()->GetAsString(&callback_id));
+ EXPECT_EQ(expected_callback_id, callback_id);
+
+ std::string actual_status;
+ ASSERT_TRUE(data.arg3()->GetAsString(&actual_status));
+ EXPECT_EQ(expected_status, actual_status);
+ }
+
private:
content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_;
@@ -188,49 +207,55 @@ TEST_F(EasyUnlockSettingsHandlerTest, EnabledStatus) {
list_args.Append(new base::StringValue("test-callback-id"));
handler->HandleGetEnabledStatus(&list_args);
- std::string callback_id;
- bool enabled_status;
-
EXPECT_EQ(3U, web_ui()->call_data().size());
const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
EXPECT_EQ("cr.webUIResponse", data.function_name());
+ std::string callback_id;
ASSERT_TRUE(data.arg1()->GetAsString(&callback_id));
EXPECT_EQ("test-callback-id", callback_id);
- ASSERT_TRUE(data.arg2()->GetAsBoolean(&enabled_status));
+ bool enabled_status = false;
+ ASSERT_TRUE(data.arg3()->GetAsBoolean(&enabled_status));
EXPECT_TRUE(enabled_status);
}
-TEST_F(EasyUnlockSettingsHandlerTest, TurnOffStatus) {
+TEST_F(EasyUnlockSettingsHandlerTest, TurnOffFlowStatus) {
scoped_ptr<EasyUnlockSettingsHandler> handler;
handler.reset(new TestEasyUnlockSettingsHandler(profile()));
handler->set_web_ui(web_ui());
// Send an initial status query to turn on service observer.
- base::ListValue list_args;
- list_args.Append(new base::StringValue("test-callback-id"));
- handler->HandleGetEnabledStatus(&list_args);
+ base::ListValue list_args1;
+ list_args1.Append(new base::StringValue("test-callback-id-1"));
+ handler->HandleGetEnabledStatus(&list_args1);
EXPECT_EQ(1U, web_ui()->call_data().size());
- handler->HandleGetTurnOffFlowStatus(nullptr);
- VerifyTurnOffStatusCallback(2U, "idle");
+ base::ListValue list_args2;
+ list_args2.Append(new base::StringValue("test-callback-id-2"));
+ handler->HandleGetTurnOffFlowStatus(&list_args2);
+ VerifyTurnOffFlowStatusWebUIResponse(2U, "test-callback-id-2", "idle");
- handler->HandleRequestTurnOff(nullptr);
- VerifyTurnOffStatusCallback(3U, "pending");
+ handler->HandleStartTurnOffFlow(nullptr);
+ VerifyTurnOffFlowStatusWebUIListenerCallback(3U, "pending");
- handler->HandleGetTurnOffFlowStatus(nullptr);
- VerifyTurnOffStatusCallback(4U, "pending");
+ base::ListValue list_args3;
+ list_args3.Append(new base::StringValue("test-callback-id-3"));
+ handler->HandleGetTurnOffFlowStatus(&list_args3);
+ VerifyTurnOffFlowStatusWebUIResponse(4U, "test-callback-id-3", "pending");
- handler->HandlePageDismissed(nullptr);
- VerifyTurnOffStatusCallback(5U, "idle");
+ handler->HandleCancelTurnOffFlow(nullptr);
+ VerifyTurnOffFlowStatusWebUIListenerCallback(5U, "idle");
- fake_easy_unlock_service()->SetTurnOffFailForTest();
- VerifyTurnOffStatusCallback(6U, "server-error");
+ fake_easy_unlock_service()->SetTurnOffFlowFailForTest();
+ VerifyTurnOffFlowStatusWebUIListenerCallback(6U, "server-error");
- handler->HandleGetTurnOffFlowStatus(nullptr);
- VerifyTurnOffStatusCallback(7U, "server-error");
+ base::ListValue list_args4;
+ list_args4.Append(new base::StringValue("test-callback-id-4"));
+ handler->HandleGetTurnOffFlowStatus(&list_args4);
+ VerifyTurnOffFlowStatusWebUIResponse(7U, "test-callback-id-4",
+ "server-error");
}
} // namespace settings
diff --git a/chrome/test/data/webui/settings/easy_unlock_browsertest_chromeos.js b/chrome/test/data/webui/settings/easy_unlock_browsertest_chromeos.js
index f4fb413..25d1edf 100644
--- a/chrome/test/data/webui/settings/easy_unlock_browsertest_chromeos.js
+++ b/chrome/test/data/webui/settings/easy_unlock_browsertest_chromeos.js
@@ -46,7 +46,7 @@ TEST_F('SettingsEasyUnlockBrowserTest', 'MAYBE_EasyUnlock', function() {
var TestEasyUnlockBrowserProxy = function() {
settings.TestBrowserProxy.call(this, [
'getEnabledStatus',
- 'launchSetup',
+ 'startTurnOnFlow',
]);
/** @private {boolean} */
@@ -70,8 +70,8 @@ TEST_F('SettingsEasyUnlockBrowserTest', 'MAYBE_EasyUnlock', function() {
},
/** @override */
- launchSetup: function() {
- this.methodCalled('launchSetup');
+ startTurnOnFlow: function() {
+ this.methodCalled('startTurnOnFlow');
},
};
@@ -126,7 +126,7 @@ TEST_F('SettingsEasyUnlockBrowserTest', 'MAYBE_EasyUnlock', function() {
assertTrue(!!setupButton);
MockInteractions.tap(setupButton);
- return browserProxy.whenCalled('launchSetup');
+ return browserProxy.whenCalled('startTurnOnFlow');
});
});
});