forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LoginScreenExtensionUiHandlerBrowsertest
The browser test checks that an installed extension with permissions can call the chrome.loginScreenUi APIs. The tests are: - check that a window can be opened - check that multiple windows cannot be opened - check that a window can be opened and closed - check that calling close fails when there is no open window whitelisted_extension has been updated for the test logic. Change-Id: I51be44d8bcf2089e77d39b8e4f2753e80576f7a3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1640406 Reviewed-by: Alexander Hendrich <hendrich@chromium.org> Reviewed-by: Devlin <rdevlin.cronin@chromium.org> Commit-Queue: Jit Yao Yap <jityao@google.com> Cr-Commit-Position: refs/heads/master@{#669623}
- Loading branch information
Jit Yao Yap
authored and
Commit Bot
committed
Jun 17, 2019
1 parent
b127cb7
commit f89d5ff
Showing
8 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
...wser/chromeos/extensions/login_screen_ui/login_screen_extension_ui_handler_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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 "chrome/browser/chromeos/extensions/login_screen_ui/login_screen_extension_ui_handler.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "base/logging.h" | ||
#include "base/macros.h" | ||
#include "chrome/browser/chromeos/extensions/login_screen_ui/login_screen_extension_ui_handler.h" | ||
#include "chrome/browser/chromeos/policy/signin_profile_extensions_policy_test_base.h" | ||
#include "components/version_info/version_info.h" | ||
#include "extensions/test/extension_test_message_listener.h" | ||
#include "extensions/test/result_catcher.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace { | ||
|
||
// The extension files can be found under the directory | ||
// chrome/test/data/extensions/api_test/login_screen_ui/whitelisted_extension/ | ||
// This extension has been whitelisted to use the chrome.loginScreenUi API | ||
// under chrome/common/extensions/api/_permission_features.json | ||
const char kExtensionId[] = "oclffehlkdgibkainkilopaalpdobkan"; | ||
const char kExtensionUpdateManifestPath[] = | ||
"/extensions/api_test/login_screen_ui/update_manifest.xml"; | ||
|
||
const char kWaitingForTestName[] = "Waiting for test name"; | ||
|
||
const char kCanOpenWindow[] = "CanOpenWindow"; | ||
const char kCannotOpenMultipleWindows[] = "CannotOpenMultipleWindows"; | ||
const char kCanOpenAndCloseWindow[] = "CanOpenAndCloseWindow"; | ||
const char kCannotCloseNoWindow[] = "CannotCloseNoWindow"; | ||
|
||
} // namespace | ||
|
||
namespace chromeos { | ||
|
||
class LoginScreenExtensionUiHandlerBrowsertest | ||
: public policy::SigninProfileExtensionsPolicyTestBase { | ||
public: | ||
LoginScreenExtensionUiHandlerBrowsertest() | ||
: SigninProfileExtensionsPolicyTestBase(version_info::Channel::DEV) {} | ||
|
||
~LoginScreenExtensionUiHandlerBrowsertest() override = default; | ||
|
||
void SetUpExtensionAndRunTest(std::string testName) { | ||
extensions::ResultCatcher catcher; | ||
|
||
ExtensionTestMessageListener listener(kWaitingForTestName, | ||
/*will_reply=*/true); | ||
|
||
AddExtensionForForceInstallation(kExtensionId, | ||
kExtensionUpdateManifestPath); | ||
|
||
ASSERT_TRUE(listener.WaitUntilSatisfied()); | ||
listener.Reply(testName); | ||
|
||
ASSERT_TRUE(catcher.GetNextResult()); | ||
} | ||
|
||
bool HasOpenWindow() { | ||
LoginScreenExtensionUiHandler* ui_handler = | ||
LoginScreenExtensionUiHandler::Get(false); | ||
CHECK(ui_handler); | ||
return ui_handler->HasOpenWindow(kExtensionId); | ||
} | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(LoginScreenExtensionUiHandlerBrowsertest); | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(LoginScreenExtensionUiHandlerBrowsertest, | ||
ExtensionCanOpenWindow) { | ||
SetUpExtensionAndRunTest(kCanOpenWindow); | ||
EXPECT_TRUE(HasOpenWindow()); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(LoginScreenExtensionUiHandlerBrowsertest, | ||
ExtensionCannotOpenMultipleWindows) { | ||
SetUpExtensionAndRunTest(kCannotOpenMultipleWindows); | ||
EXPECT_TRUE(HasOpenWindow()); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(LoginScreenExtensionUiHandlerBrowsertest, | ||
ExtensionCanOpenAndCloseWindow) { | ||
SetUpExtensionAndRunTest(kCanOpenAndCloseWindow); | ||
EXPECT_FALSE(HasOpenWindow()); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(LoginScreenExtensionUiHandlerBrowsertest, | ||
ExtensionCannotCloseNoWindow) { | ||
SetUpExtensionAndRunTest(kCannotCloseNoWindow); | ||
EXPECT_FALSE(HasOpenWindow()); | ||
} | ||
|
||
} // namespace chromeos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
chrome/test/data/extensions/api_test/login_screen_ui/update_manifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- | ||
This update manifest points to the ./extension.crx file. "mock.http" is a | ||
placeholder that gets substituted with the test server address in runtime. | ||
--> | ||
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'> | ||
<app appid='oclffehlkdgibkainkilopaalpdobkan'> | ||
<updatecheck | ||
codebase='http://mock.http/extensions/api_test/login_screen_ui/whitelisted_extension.crx' | ||
version='1.10' /> | ||
</app> | ||
</gupdate> |
Binary file modified
BIN
+1 KB
(120%)
chrome/test/data/extensions/api_test/login_screen_ui/whitelisted_extension.crx
Binary file not shown.
65 changes: 65 additions & 0 deletions
65
chrome/test/data/extensions/api_test/login_screen_ui/whitelisted_extension/background.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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. | ||
|
||
var cannotCreateMultipleWindowsErrorMessage = | ||
"Can't create more than one window per extension."; | ||
var cannotCloseNoWindowErrorMessage = "No open window to close."; | ||
|
||
var tests = { | ||
'CanOpenWindow': function CanOpenWindow() { | ||
chrome.loginScreenUi.show({url: 'some/path.html'}, function() { | ||
chrome.test.assertNoLastError(); | ||
chrome.test.succeed(); | ||
}); | ||
}, | ||
'CannotOpenMultipleWindows': function CannotOpenMultipleWindows() { | ||
chrome.loginScreenUi.show({url: 'some/path.html'}, function() { | ||
chrome.test.assertNoLastError(); | ||
chrome.loginScreenUi.show({url: 'some/path.html'}, function() { | ||
chrome.test.assertLastError(cannotCreateMultipleWindowsErrorMessage); | ||
chrome.test.succeed(); | ||
}); | ||
}); | ||
}, | ||
'CanOpenAndCloseWindow': function CanOpenAndCloseWindow() { | ||
chrome.loginScreenUi.show({url: 'some/path.html'}, function() { | ||
chrome.test.assertNoLastError(); | ||
chrome.loginScreenUi.close(function() { | ||
chrome.test.assertNoLastError(); | ||
chrome.test.succeed(); | ||
}); | ||
}); | ||
}, | ||
'CannotCloseNoWindow': function CannotCloseNoWindow() { | ||
chrome.loginScreenUi.close(function() { | ||
chrome.test.assertLastError(cannotCloseNoWindowErrorMessage); | ||
chrome.test.succeed(); | ||
}); | ||
}, | ||
}; | ||
|
||
// |waitForTestName()| waits for the browser test to reply with a test name and | ||
// runs the specified test. The browser test logic can be found at | ||
// chrome/browser/chromeos/extensions/login_screen_ui/ | ||
// login_screen_extension_ui_handler_browsertest.cc | ||
function waitForTestName(testName) { | ||
// No observer for NOTIFICATION_EXTENSION_TEST_MESSAGE or observer did not | ||
// reply with a test name. | ||
// This check is to prevent the API test under login_screen_ui_apitest.cc | ||
// from failing. This check can be removed once the API is stable and the API | ||
// test is no longer needed. | ||
if (testName === '') { | ||
return; | ||
} | ||
|
||
if (!tests.hasOwnProperty(testName) || | ||
typeof tests[testName] !== 'function') { | ||
chrome.test.fail('Test not found: ' + testName); | ||
return; | ||
} | ||
|
||
chrome.test.runTests([tests[testName]]); | ||
} | ||
|
||
chrome.test.sendMessage('Waiting for test name', waitForTestName); |
6 changes: 5 additions & 1 deletion
6
chrome/test/data/extensions/api_test/login_screen_ui/whitelisted_extension/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters