Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5007)

Unified Diff: chrome/common/extensions/manifest_handlers/automation_unittest.cc

Issue 377553003: Create a ManifestPermission implementation for Automation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Revert changes to automation_apitest.cc Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/manifest_handlers/automation_unittest.cc
diff --git a/chrome/common/extensions/manifest_handlers/automation_unittest.cc b/chrome/common/extensions/manifest_handlers/automation_unittest.cc
index 7a3062d0cf96797a595ed08fb39dff584c280b20..3c4f32ed35082a740a811b0ee2cc4bdfb78e6d06 100644
--- a/chrome/common/extensions/manifest_handlers/automation_unittest.cc
+++ b/chrome/common/extensions/manifest_handlers/automation_unittest.cc
@@ -7,7 +7,11 @@
#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/manifest_constants.h"
+#include "extensions/common/permissions/permissions_data.h"
+#include "grit/extensions_strings.h"
+#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
namespace extensions {
@@ -30,6 +34,10 @@ TEST_F(AutomationManifestTest, AsBooleanFalse) {
LoadAndExpectSuccess("automation_boolean_false.json");
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ EXPECT_EQ(0u, warnings.size());
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_FALSE(info);
}
@@ -39,12 +47,17 @@ TEST_F(AutomationManifestTest, AsBooleanTrue) {
LoadAndExpectSuccess("automation_boolean_true.json");
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(1u, warnings.size());
+ EXPECT_EQ("Read and modify your data on www.google.com",
+ base::UTF16ToUTF8(warnings[0]));
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_FALSE(info->desktop);
EXPECT_FALSE(info->interact);
- EXPECT_FALSE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}
@@ -53,12 +66,17 @@ TEST_F(AutomationManifestTest, InteractTrue) {
LoadAndExpectSuccess("automation_interact_true.json");
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(1u, warnings.size());
+ EXPECT_EQ("Read and modify your data on www.google.com",
+ base::UTF16ToUTF8(warnings[0]));
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_FALSE(info->desktop);
EXPECT_TRUE(info->interact);
- EXPECT_FALSE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}
@@ -72,12 +90,17 @@ TEST_F(AutomationManifestTest, Matches) {
URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR)));
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(1u, warnings.size());
+ EXPECT_EQ("Read and modify your data on www.google.com and www.twitter.com",
+ base::UTF16ToUTF8(warnings[0]));
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_FALSE(info->desktop);
EXPECT_FALSE(info->interact);
- EXPECT_TRUE(info->specified_matches);
EXPECT_FALSE(info->matches.is_empty());
EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/")));
@@ -89,18 +112,45 @@ TEST_F(AutomationManifestTest, Matches) {
EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com")));
}
+TEST_F(AutomationManifestTest, MatchesAndPermissions) {
+ scoped_refptr<Extension> extension =
+ LoadAndExpectSuccess("automation_matches_and_permissions.json");
+ ASSERT_TRUE(extension.get());
+
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(2u, warnings.size());
+ EXPECT_EQ("Read and modify your data on www.google.com",
+ base::UTF16ToUTF8(warnings[0]));
+ EXPECT_EQ("Read and modify your data on www.twitter.com",
+ base::UTF16ToUTF8(warnings[1]));
+
+ const AutomationInfo* info = AutomationInfo::Get(extension.get());
+ ASSERT_TRUE(info);
+
+ EXPECT_FALSE(info->desktop);
+ EXPECT_FALSE(info->interact);
+ EXPECT_FALSE(info->matches.is_empty());
+
+ EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/")));
+ EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com")));
+}
+
TEST_F(AutomationManifestTest, EmptyMatches) {
scoped_refptr<Extension> extension =
LoadAndExpectWarning("automation_empty_matches.json",
automation_errors::kErrorNoMatchesProvided);
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ EXPECT_EQ(0u, warnings.size());
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_FALSE(info->desktop);
EXPECT_FALSE(info->interact);
- EXPECT_TRUE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}
@@ -120,12 +170,15 @@ TEST_F(AutomationManifestTest, NoValidMatches) {
EXPECT_EQ(automation_errors::kErrorNoMatchesProvided,
extension->install_warnings()[1].message);
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(0u, warnings.size());
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_FALSE(info->desktop);
EXPECT_FALSE(info->interact);
- EXPECT_TRUE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}
@@ -134,12 +187,17 @@ TEST_F(AutomationManifestTest, DesktopFalse) {
LoadAndExpectSuccess("automation_desktop_false.json");
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(1u, warnings.size());
+ EXPECT_EQ("Read and modify your data on www.google.com",
+ base::UTF16ToUTF8(warnings[0]));
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_FALSE(info->desktop);
EXPECT_FALSE(info->interact);
- EXPECT_FALSE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}
@@ -148,12 +206,17 @@ TEST_F(AutomationManifestTest, DesktopTrue) {
LoadAndExpectSuccess("automation_desktop_true.json");
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(1u, warnings.size());
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS),
+ warnings[0]);
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_TRUE(info->desktop);
EXPECT_TRUE(info->interact);
- EXPECT_FALSE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}
@@ -161,13 +224,17 @@ TEST_F(AutomationManifestTest, Desktop_InteractTrue) {
scoped_refptr<Extension> extension =
LoadAndExpectSuccess("automation_desktop_interact_true.json");
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(1u, warnings.size());
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS),
+ warnings[0]);
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_TRUE(info->desktop);
EXPECT_TRUE(info->interact);
- EXPECT_FALSE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}
@@ -177,12 +244,17 @@ TEST_F(AutomationManifestTest, Desktop_InteractFalse) {
automation_errors::kErrorDesktopTrueInteractFalse);
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(1u, warnings.size());
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS),
+ warnings[0]);
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_TRUE(info->desktop);
EXPECT_TRUE(info->interact);
- EXPECT_FALSE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}
@@ -192,12 +264,17 @@ TEST_F(AutomationManifestTest, Desktop_MatchesSpecified) {
automation_errors::kErrorDesktopTrueMatchesSpecified);
ASSERT_TRUE(extension.get());
+ std::vector<base::string16> warnings =
+ extension->permissions_data()->GetPermissionMessageStrings();
+ ASSERT_EQ(1u, warnings.size());
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS),
+ warnings[0]);
+
const AutomationInfo* info = AutomationInfo::Get(extension.get());
ASSERT_TRUE(info);
EXPECT_TRUE(info->desktop);
EXPECT_TRUE(info->interact);
- EXPECT_FALSE(info->specified_matches);
EXPECT_TRUE(info->matches.is_empty());
}

Powered by Google App Engine
This is Rietveld 408576698