Commit d84d10b0 authored by khmel@chromium.org's avatar khmel@chromium.org Committed by Commit Bot

arc: Add autotest method to return ARC provisioning state.

This allows not to use expensive and fragile set of adb commands and
returns ARC provisioning state as it appears in Chrome.

TEST=in context of crrev.com/i/717828
BUG=b:119349367

Change-Id: I3582fcca3e36a084dbe8e0ff3522930504ebeb85
Reviewed-on: https://chromium-review.googlesource.com/c/1340797Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Yury Khmel <khmel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608980}
parent 26e4871d
...@@ -683,6 +683,20 @@ ExtensionFunction::ResponseAction AutotestPrivateIsAppShownFunction::Run() { ...@@ -683,6 +683,20 @@ ExtensionFunction::ResponseAction AutotestPrivateIsAppShownFunction::Run() {
OneArgument(std::make_unique<base::Value>(window_attached))); OneArgument(std::make_unique<base::Value>(window_attached)));
} }
///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateIsAppShownFunction
///////////////////////////////////////////////////////////////////////////////
AutotestPrivateIsArcProvisionedFunction::
~AutotestPrivateIsArcProvisionedFunction() = default;
ExtensionFunction::ResponseAction
AutotestPrivateIsArcProvisionedFunction::Run() {
DVLOG(1) << "AutotestPrivateIsArcProvisionedFunction";
return RespondNow(OneArgument(std::make_unique<base::Value>(
arc::IsArcProvisioned(Profile::FromBrowserContext(browser_context())))));
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateLaunchAppFunction // AutotestPrivateLaunchAppFunction
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
......
...@@ -256,6 +256,17 @@ class AutotestPrivateIsAppShownFunction : public UIThreadExtensionFunction { ...@@ -256,6 +256,17 @@ class AutotestPrivateIsAppShownFunction : public UIThreadExtensionFunction {
ResponseAction Run() override; ResponseAction Run() override;
}; };
class AutotestPrivateIsArcProvisionedFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("autotestPrivate.isArcProvisioned",
AUTOTESTPRIVATE_ISARCPROVISIONED)
private:
~AutotestPrivateIsArcProvisionedFunction() override;
ResponseAction Run() override;
};
class AutotestPrivateLaunchAppFunction : public UIThreadExtensionFunction { class AutotestPrivateLaunchAppFunction : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("autotestPrivate.launchApp", DECLARE_EXTENSION_FUNCTION("autotestPrivate.launchApp",
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "chrome/browser/chromeos/extensions/autotest_private/autotest_private_api.h" #include "chrome/browser/chromeos/extensions/autotest_private/autotest_private_api.h"
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "components/arc/arc_prefs.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
namespace extensions { namespace extensions {
...@@ -37,7 +38,20 @@ IN_PROC_BROWSER_TEST_F(AutotestPrivateApiTest, AutotestPrivate) { ...@@ -37,7 +38,20 @@ IN_PROC_BROWSER_TEST_F(AutotestPrivateApiTest, AutotestPrivate) {
AutotestPrivateAPI::GetFactoryInstance() AutotestPrivateAPI::GetFactoryInstance()
->Get(browser()->profile()) ->Get(browser()->profile())
->set_test_mode(true); ->set_test_mode(true);
ASSERT_TRUE(RunComponentExtensionTest("autotest_private")) << message_; ASSERT_TRUE(RunComponentExtensionTestWithArg("autotest_private", "default"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AutotestPrivateApiTest, AutotestPrivateArcProvisioned) {
// Turn on testing mode so we don't kill the browser.
AutotestPrivateAPI::GetFactoryInstance()
->Get(browser()->profile())
->set_test_mode(true);
// Provisioning is completed.
browser()->profile()->GetPrefs()->SetBoolean(arc::prefs::kArcSignedIn, true);
ASSERT_TRUE(
RunComponentExtensionTestWithArg("autotest_private", "arcProvisioned"))
<< message_;
} }
} // namespace extensions } // namespace extensions
...@@ -231,6 +231,13 @@ bool ExtensionApiTest::RunComponentExtensionTest( ...@@ -231,6 +231,13 @@ bool ExtensionApiTest::RunComponentExtensionTest(
kFlagEnableFileAccess | kFlagLoadAsComponent); kFlagEnableFileAccess | kFlagLoadAsComponent);
} }
bool ExtensionApiTest::RunComponentExtensionTestWithArg(
const std::string& extension_name,
const char* custom_arg) {
return RunExtensionTestImpl(extension_name, std::string(), custom_arg,
kFlagEnableFileAccess | kFlagLoadAsComponent);
}
bool ExtensionApiTest::RunExtensionTestNoFileAccess( bool ExtensionApiTest::RunExtensionTestNoFileAccess(
const std::string& extension_name) { const std::string& extension_name) {
return RunExtensionTestImpl(extension_name, std::string(), NULL, kFlagNone); return RunExtensionTestImpl(extension_name, std::string(), NULL, kFlagNone);
......
...@@ -98,6 +98,10 @@ class ExtensionApiTest : public ExtensionBrowserTest { ...@@ -98,6 +98,10 @@ class ExtensionApiTest : public ExtensionBrowserTest {
// Same as RunExtensionTest, but loads extension as component. // Same as RunExtensionTest, but loads extension as component.
bool RunComponentExtensionTest(const std::string& extension_name); bool RunComponentExtensionTest(const std::string& extension_name);
// Same as RunComponentExtensionTest, but provides extra arg.
bool RunComponentExtensionTestWithArg(const std::string& extension_name,
const char* custom_arg);
// Same as RunExtensionTest, but disables file access. // Same as RunExtensionTest, but disables file access.
bool RunExtensionTestNoFileAccess(const std::string& extension_name); bool RunExtensionTestNoFileAccess(const std::string& extension_name);
......
...@@ -104,6 +104,8 @@ namespace autotestPrivate { ...@@ -104,6 +104,8 @@ namespace autotestPrivate {
callback IsAppShownCallback = void (boolean appShown); callback IsAppShownCallback = void (boolean appShown);
callback IsArcProvisionedCallback = void (boolean arcProvisioned);
callback TakeScreenshotCallback = void (DOMString base64Png); callback TakeScreenshotCallback = void (DOMString base64Png);
callback VoidCallback = void (); callback VoidCallback = void ();
...@@ -175,6 +177,9 @@ namespace autotestPrivate { ...@@ -175,6 +177,9 @@ namespace autotestPrivate {
// Returns true if requested app is shown in Chrome. // Returns true if requested app is shown in Chrome.
static void isAppShown(DOMString appId, IsAppShownCallback callback); static void isAppShown(DOMString appId, IsAppShownCallback callback);
// Returns true if ARC is provisioned.
static void isArcProvisioned(IsArcProvisionedCallback callback);
// Launches an application from the launcher with the given appId. // Launches an application from the launcher with the given appId.
static void launchApp(DOMString appId, VoidCallback callback); static void launchApp(DOMString appId, VoidCallback callback);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
chrome.test.runTests([ var defaultTests = [
// logout/restart/shutdown don't do anything as we don't want to kill the // logout/restart/shutdown don't do anything as we don't want to kill the
// browser with these tests. // browser with these tests.
function logout() { function logout() {
...@@ -212,4 +212,41 @@ chrome.test.runTests([ ...@@ -212,4 +212,41 @@ chrome.test.runTests([
chrome.test.callbackFail( chrome.test.callbackFail(
'Assistant is not available for the current user')); 'Assistant is not available for the current user'));
}, },
]); // This test verifies that ARC is not provisioned by default.
function isArcProvisioned() {
chrome.autotestPrivate.isArcProvisioned(
function(arcProvisioned) {
chrome.test.assertFalse(arcProvisioned);
chrome.test.assertNoLastError();
chrome.test.succeed();
});
},
];
var arcProvisionedTests = [
// This test verifies that isArcProvisioned returns True in case ARC
// provisiong is done.
function isArcProvisioned() {
chrome.autotestPrivate.isArcProvisioned(
function(arcProvisioned) {
chrome.test.assertTrue(arcProvisioned);
chrome.test.assertNoLastError();
chrome.test.succeed();
});
},
];
var test_suites = {
'default': defaultTests,
'arcProvisioned': arcProvisionedTests
};
chrome.test.getConfig(function(config) {
var suite = test_suites[config.customArg];
if (config.customArg in test_suites) {
chrome.test.runTests(test_suites[config.customArg]);
} else {
chrome.test.fail('Invalid test suite');
}
});
...@@ -1353,6 +1353,7 @@ enum HistogramValue { ...@@ -1353,6 +1353,7 @@ enum HistogramValue {
TABS_GOBACK = 1290, TABS_GOBACK = 1290,
BRAILLEDISPLAYPRIVATE_UPDATEBLUETOOTHBRAILLEDISPLAYADDRESS = 1291, BRAILLEDISPLAYPRIVATE_UPDATEBLUETOOTHBRAILLEDISPLAYADDRESS = 1291,
AUTOTESTPRIVATE_SETASSISTANTENABLED = 1292, AUTOTESTPRIVATE_SETASSISTANTENABLED = 1292,
AUTOTESTPRIVATE_ISARCPROVISIONED = 1293,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -17276,6 +17276,7 @@ Called by update_net_error_codes.py.--> ...@@ -17276,6 +17276,7 @@ Called by update_net_error_codes.py.-->
<int value="1291" <int value="1291"
label="BRAILLEDISPLAYPRIVATE_UPDATEBLUETOOTHBRAILLEDISPLAYADDRESS"/> label="BRAILLEDISPLAYPRIVATE_UPDATEBLUETOOTHBRAILLEDISPLAYADDRESS"/>
<int value="1292" label="AUTOTESTPRIVATE_SETASSISTANTENABLED"/> <int value="1292" label="AUTOTESTPRIVATE_SETASSISTANTENABLED"/>
<int value="1293" label="AUTOTESTPRIVATE_ISARCPROVISIONED"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
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