i18n_apitest.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/file_util.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/files/file_path.h" 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/files/scoped_temp_dir.h" 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/extensions/extension_apitest.h" 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/test/base/ui_test_utils.h" 127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "extensions/common/extension.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "net/test/embedded_test_server/embedded_test_server.h" 145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ExtensionApiTest, I18N) { 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_TRUE(StartEmbeddedTestServer()); 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_TRUE(RunExtensionTest("i18n")) << message_; 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ExtensionApiTest, I18NUpdate) { 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Create an Extension whose messages.json file will be updated. 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::ScopedTempDir extension_dir; 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::CopyFile( 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) test_data_dir_.AppendASCII("i18nUpdate") 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) .AppendASCII("manifest.json"), 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) extension_dir.path().AppendASCII("manifest.json")); 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::CopyFile( 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) test_data_dir_.AppendASCII("i18nUpdate") 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) .AppendASCII("contentscript.js"), 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) extension_dir.path().AppendASCII("contentscript.js")); 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::CopyDirectory( 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) test_data_dir_.AppendASCII("i18nUpdate") 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) .AppendASCII("_locales"), 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) extension_dir.path().AppendASCII("_locales"), 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) true); 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const extensions::Extension* extension = LoadExtension(extension_dir.path()); 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ResultCatcher catcher; 42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Test that the messages.json file is loaded and the i18n message is loaded. 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ui_test_utils::NavigateToURL( 455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) browser(), 465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) embedded_test_server()->GetURL("/extensions/test_file.html")); 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(catcher.GetNextResult()); 48 49 base::string16 title; 50 ui_test_utils::GetCurrentTabTitle(browser(), &title); 51 EXPECT_EQ(std::string("FIRSTMESSAGE"), UTF16ToUTF8(title)); 52 53 // Change messages.json file and reload extension. 54 base::CopyFile( 55 test_data_dir_.AppendASCII("i18nUpdate") 56 .AppendASCII("messages2.json"), 57 extension_dir.path().AppendASCII("_locales/en/messages.json")); 58 ReloadExtension(extension->id()); 59 60 // Check that the i18n message is also changed. 61 ui_test_utils::NavigateToURL( 62 browser(), 63 embedded_test_server()->GetURL("/extensions/test_file.html")); 64 EXPECT_TRUE(catcher.GetNextResult()); 65 66 ui_test_utils::GetCurrentTabTitle(browser(), &title); 67 EXPECT_EQ(std::string("SECONDMESSAGE"), UTF16ToUTF8(title)); 68} 69