1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/common/manifest_handlers/automation.h"
#include "base/command_line.h"
#include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
#include "chrome/grit/generated_resources.h"
#include "components/version_info/version_info.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/features/feature_channel.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/permissions/permission_message_test_util.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
namespace extensions {
class AutomationManifestTest : public ChromeManifestTest {
public:
AutomationManifestTest() : channel_(version_info::Channel::UNKNOWN) {}
protected:
AutomationInfo* GetAutomationInfo(scoped_refptr<Extension> extension) {
return static_cast<AutomationInfo*>(
extension->GetManifestData(manifest_keys::kAutomation));
}
private:
void SetUp() override {
auto* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII(
extensions::switches::kAllowlistedExtensionID,
"ddchlicdkolnonkihahngkmmmjnjlkkf");
}
ScopedCurrentChannel channel_;
};
TEST_F(AutomationManifestTest, AsBooleanFalse) {
scoped_refptr<Extension> extension =
LoadAndExpectSuccess("automation_boolean_false.json");
ASSERT_TRUE(extension.get());
EXPECT_TRUE(VerifyNoPermissionMessages(extension->permissions_data()));
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_FALSE(info);
}
TEST_F(AutomationManifestTest, AsBooleanTrue) {
scoped_refptr<Extension> extension =
LoadAndExpectSuccess("automation_boolean_true.json");
ASSERT_TRUE(extension.get());
EXPECT_TRUE(VerifyOnePermissionMessage(
extension->permissions_data(),
"Read and change your data on www.google.com"));
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_FALSE(info->desktop);
}
TEST_F(AutomationManifestTest, DesktopFalse) {
scoped_refptr<Extension> extension =
LoadAndExpectSuccess("automation_desktop_false.json");
ASSERT_TRUE(extension.get());
EXPECT_TRUE(VerifyOnePermissionMessage(
extension->permissions_data(),
"Read and change your data on www.google.com"));
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_FALSE(info->desktop);
}
TEST_F(AutomationManifestTest, DesktopTrue) {
scoped_refptr<Extension> extension =
LoadAndExpectSuccess("automation_desktop_true.json");
ASSERT_TRUE(extension.get());
EXPECT_TRUE(VerifyOnePermissionMessage(
extension->permissions_data(),
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS)));
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_TRUE(info->desktop);
}
} // namespace extensions
|