0

Delete the extensions i18n message map cache when extension unload is received.

Invalidate the messages map for the extension in case the extension is reloaded
with a new messages map.

BUG=53628
TEST=Load an unpacked extension with i18n messages used in a content script.
Open a window or tab that loads the i18n messages. Change the messages.json
file. Reload the extension and the messages should be changed.

Review URL: https://chromiumcodereview.appspot.com/12319073

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188460 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
patrickriordan177@gmail.com
2013-03-15 20:12:20 +00:00
parent 981d9b8508
commit 9e66b7978c
9 changed files with 98 additions and 1 deletions
AUTHORS
chrome
browser
extensions
common
renderer
extensions
test
data
extensions

@ -231,4 +231,5 @@ Johannes Rudolph <johannes.rudolph@googlemail.com>
Aaron Jacobs <samusaaron3@gmail.com>
Sam Larison <qufighter@gmail.com>
Jun Jiang <jun.a.jiang@intel.com>
Bobby Powers <bobbypowers@gmail.com>
Bobby Powers <bobbypowers@gmail.com>
Patrick Riordan <patrickriordan177@gmail.com>

@ -2,9 +2,65 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/test/base/ui_test_utils.h"
#include "net/test/test_server.h"
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, I18N) {
ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("i18n")) << message_;
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, I18NUpdate) {
ASSERT_TRUE(StartTestServer());
// Create an Extension whose messages.json file will be updated.
base::ScopedTempDir extension_dir;
ASSERT_TRUE(extension_dir.CreateUniqueTempDir());
file_util::CopyFile(
test_data_dir_.AppendASCII("i18nUpdate")
.AppendASCII("manifest.json"),
extension_dir.path().AppendASCII("manifest.json"));
file_util::CopyFile(
test_data_dir_.AppendASCII("i18nUpdate")
.AppendASCII("contentscript.js"),
extension_dir.path().AppendASCII("contentscript.js"));
file_util::CopyDirectory(
test_data_dir_.AppendASCII("i18nUpdate")
.AppendASCII("_locales"),
extension_dir.path().AppendASCII("_locales"),
true);
const extensions::Extension* extension = LoadExtension(extension_dir.path());
ResultCatcher catcher;
// Test that the messages.json file is loaded and the i18n message is loaded.
ui_test_utils::NavigateToURL(
browser(), test_server()->GetURL("file/extensions/test_file.html"));
EXPECT_TRUE(catcher.GetNextResult());
string16 title;
ui_test_utils::GetCurrentTabTitle(browser(), &title);
EXPECT_EQ(std::string("FIRSTMESSAGE"), UTF16ToUTF8(title));
// Change messages.json file and reload extension.
file_util::CopyFile(
test_data_dir_.AppendASCII("i18nUpdate")
.AppendASCII("messages2.json"),
extension_dir.path().AppendASCII("_locales/en/messages.json"));
ReloadExtension(extension->id());
// Check that the i18n message is also changed.
ui_test_utils::NavigateToURL(
browser(), test_server()->GetURL("file/extensions/test_file.html"));
EXPECT_TRUE(catcher.GetNextResult());
ui_test_utils::GetCurrentTabTitle(browser(), &title);
EXPECT_EQ(std::string("SECONDMESSAGE"), UTF16ToUTF8(title));
}

@ -341,4 +341,8 @@ L10nMessagesMap* GetL10nMessagesMap(const std::string& extension_id) {
return NULL;
}
void EraseL10nMessagesMap(const std::string& extension_id) {
g_extension_to_messages_map.Get().messages_map.erase(extension_id);
}
} // namespace extensions

@ -165,6 +165,9 @@ ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap();
// Returns message map that matches given extension_id, or NULL.
L10nMessagesMap* GetL10nMessagesMap(const std::string& extension_id);
// Erases the L10nMessagesMap for the given |extension_id|.
void EraseL10nMessagesMap(const std::string& extension_id);
} // namsepace extensions
#endif // CHROME_COMMON_EXTENSIONS_MESSAGE_BUNDLE_H_

@ -18,6 +18,7 @@
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/features/feature.h"
#include "chrome/common/extensions/manifest.h"
#include "chrome/common/extensions/message_bundle.h"
#include "chrome/common/extensions/permissions/permission_set.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/view_type.h"
@ -579,6 +580,10 @@ void Dispatcher::OnUnloaded(const std::string& id) {
v8_context_set_.OnExtensionUnloaded(id);
// Invalidates the messages map for the extension in case the extension is
// reloaded with a new messages map.
EraseL10nMessagesMap(id);
// We don't do anything with existing platform-app stylesheets. They will
// stay resident, but the URL pattern corresponding to the unloaded
// extension's URL just won't match anything anymore.

@ -0,0 +1,5 @@
{
"testMessage": {
"message": "FIRSTMESSAGE"
}
}

@ -0,0 +1,6 @@
// Copyright (c) 2013 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.
document.title = chrome.i18n.getMessage("testMessage");
chrome.test.notifyPass();

@ -0,0 +1,12 @@
{
"name": "i18n Message Test",
"version": "1.0",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contentscript.js"]
}
],
"default_locale": "en",
"manifest_version": 2
}

@ -0,0 +1,5 @@
{
"testMessage": {
"message": "SECONDMESSAGE"
}
}