1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/test/result_catcher.h"
14 #include "net/test/embedded_test_server/embedded_test_server.h"
16 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, I18N
) {
17 ASSERT_TRUE(StartEmbeddedTestServer());
18 ASSERT_TRUE(RunExtensionTest("i18n")) << message_
;
21 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, I18NUpdate
) {
22 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
23 // Create an Extension whose messages.json file will be updated.
24 base::ScopedTempDir extension_dir
;
25 ASSERT_TRUE(extension_dir
.CreateUniqueTempDir());
27 test_data_dir_
.AppendASCII("i18nUpdate")
28 .AppendASCII("manifest.json"),
29 extension_dir
.path().AppendASCII("manifest.json"));
31 test_data_dir_
.AppendASCII("i18nUpdate")
32 .AppendASCII("contentscript.js"),
33 extension_dir
.path().AppendASCII("contentscript.js"));
35 test_data_dir_
.AppendASCII("i18nUpdate")
36 .AppendASCII("_locales"),
37 extension_dir
.path().AppendASCII("_locales"),
40 const extensions::Extension
* extension
= LoadExtension(extension_dir
.path());
42 extensions::ResultCatcher catcher
;
44 // Test that the messages.json file is loaded and the i18n message is loaded.
45 ui_test_utils::NavigateToURL(
47 embedded_test_server()->GetURL("/extensions/test_file.html"));
48 EXPECT_TRUE(catcher
.GetNextResult());
51 ui_test_utils::GetCurrentTabTitle(browser(), &title
);
52 EXPECT_EQ(std::string("FIRSTMESSAGE"), base::UTF16ToUTF8(title
));
54 // Change messages.json file and reload extension.
56 test_data_dir_
.AppendASCII("i18nUpdate")
57 .AppendASCII("messages2.json"),
58 extension_dir
.path().AppendASCII("_locales/en/messages.json"));
59 ReloadExtension(extension
->id());
61 // Check that the i18n message is also changed.
62 ui_test_utils::NavigateToURL(
64 embedded_test_server()->GetURL("/extensions/test_file.html"));
65 EXPECT_TRUE(catcher
.GetNextResult());
67 ui_test_utils::GetCurrentTabTitle(browser(), &title
);
68 EXPECT_EQ(std::string("SECONDMESSAGE"), base::UTF16ToUTF8(title
));