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

Unified Diff: chrome/browser/extensions/extension_loading_browsertest.cc

Issue 2950203002: Add new permission string for extensions that override new tab pages. (Closed)
Patch Set: Devlin feedback. Created 3 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/browser/extensions/extension_loading_browsertest.cc
diff --git a/chrome/browser/extensions/extension_loading_browsertest.cc b/chrome/browser/extensions/extension_loading_browsertest.cc
index 095be6cd6e1b2ca56269b23949a78677ea1478d6..a5828e38928a8cbe01d11b33cc1ded6d998aec3d 100644
--- a/chrome/browser/extensions/extension_loading_browsertest.cc
+++ b/chrome/browser/extensions/extension_loading_browsertest.cc
@@ -21,6 +21,7 @@
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_manager.h"
+#include "extensions/common/permissions/permissions_data.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -101,6 +102,69 @@ IN_PROC_BROWSER_TEST_F(ExtensionLoadingTest,
EXPECT_TRUE(registry->enabled_extensions().Contains(new_tab_extension->id()));
}
+IN_PROC_BROWSER_TEST_F(ExtensionLoadingTest,
+ UpgradeAddingNewTabPagePermissionNoPrompt) {
+ embedded_test_server()->ServeFilesFromDirectory(
+ base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
+ ASSERT_TRUE(embedded_test_server()->Start());
+
+ TestExtensionDir extension_dir;
+ const char manifest_template[] =
Devlin 2017/07/18 22:27:26 nit: POD-constant-style-naming: kManifestTemplate
robertshield 2017/07/19 21:02:57 Done.
+ "{"
+ " 'name': 'Overrides New Tab',"
+ " 'version': '%d',"
+ " 'description': 'Will override New Tab soon',"
+ " 'manifest_version': 2,"
+ " %s" // Placeholder for future NTP url override block.
+ " 'background': {"
Devlin 2017/07/18 22:27:27 Do we need a background at all?
robertshield 2017/07/19 21:02:57 Done.
+ " 'persistent': false,"
+ " 'scripts': ['event.js']"
+ " }"
+ "}";
+ extension_dir.WriteManifestWithSingleQuotes(
+ base::StringPrintf(manifest_template, 1, ""));
+ extension_dir.WriteFile(FILE_PATH_LITERAL("event.js"), "");
+ extension_dir.WriteFile(FILE_PATH_LITERAL("newtab.html"),
+ "<h1>Overridden New Tab Page</h1>");
+
+ const Extension* new_tab_extension =
+ InstallExtension(extension_dir.Pack(), 1 /*new install*/);
+ ASSERT_TRUE(new_tab_extension);
+
+ EXPECT_FALSE(new_tab_extension->permissions_data()->HasAPIPermission(
+ APIPermission::kNewTabPageOverride));
+
+ // Navigate that tab to a non-extension URL to swap out the extension's
+ // renderer.
+ const GURL test_link_from_ntp =
+ embedded_test_server()->GetURL("/README.chromium");
+ EXPECT_THAT(test_link_from_ntp.spec(), testing::EndsWith("/README.chromium"))
+ << "Check that the test server started.";
+ NavigateInRenderer(browser()->tab_strip_model()->GetActiveWebContents(),
+ test_link_from_ntp);
+
+ // Increase the extension's version and add the NTP url override which will
+ // add the kNewTabPageOverride permission.
+ const char ntp_override_string[] =
+ " 'chrome_url_overrides': {"
+ " 'newtab': 'newtab.html'"
+ " },";
+ extension_dir.WriteManifestWithSingleQuotes(
+ base::StringPrintf(manifest_template, 2, ntp_override_string));
+
+ // Upgrade the extension, ensure that the upgrade 'worked' in the sense that
+ // the extension is still present and not disabled and that it now has the
+ // new API permission.
Devlin 2017/07/18 22:27:27 nit: duplicate your TODO to update this?
robertshield 2017/07/19 21:02:57 Done.
+ new_tab_extension = UpdateExtension(
+ new_tab_extension->id(), extension_dir.Pack(), 0 /*expected upgrade*/);
+ ASSERT_NE(nullptr, new_tab_extension);
+
+ EXPECT_TRUE(new_tab_extension->permissions_data()->HasAPIPermission(
+ APIPermission::kNewTabPageOverride));
+ EXPECT_THAT(new_tab_extension->version()->components(),
+ testing::ElementsAre(2));
+}
+
// Tests the behavior described in http://crbug.com/532088.
IN_PROC_BROWSER_TEST_F(ExtensionLoadingTest,
KeepAliveWithDevToolsOpenOnReload) {
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/extensions/permission_message_combinations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698