diff options
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/data/extensions/subscribe_page_action/common.js | 55 | ||||
-rw-r--r-- | chrome/test/data/extensions/subscribe_page_action/options.html | 78 | ||||
-rw-r--r-- | chrome/test/data/extensions/subscribe_page_action/subscribe.html | 25 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.cc | 26 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.h | 3 |
5 files changed, 104 insertions, 83 deletions
diff --git a/chrome/test/data/extensions/subscribe_page_action/common.js b/chrome/test/data/extensions/subscribe_page_action/common.js index 7d27ca2..6752ce4 100644 --- a/chrome/test/data/extensions/subscribe_page_action/common.js +++ b/chrome/test/data/extensions/subscribe_page_action/common.js @@ -1,3 +1,7 @@ +// Copyright (c) 2010 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. + // Whether we can modify the list of readers. var storageEnabled = window.localStorage != null; @@ -32,46 +36,23 @@ function isDefaultReader(url) { } /** -* Given the tag, find if there is a __MSG_some__ message in -* innerHTML, and replace it if there is. +* Find an element with |id| and replace the text of it with i18n message with +* |msg| key. */ -function substituteMessagesForTag(tag) { - var elements = document.getElementsByTagName(tag); - if (!elements) - return; - - var message_format = "__MSG_([a-zA-Z0-9_@]+)__"; - for (i = 0; i < elements.length; i++) { - var old_text = elements[i].innerHTML.match(message_format); - if (!old_text) - continue; - - var new_text = chrome.i18n.getMessage(old_text[1]); - elements[i].innerHTML = - elements[i].innerHTML.replace(old_text[0], new_text); +function i18nReplaceImpl(id, msg, attribute) { + var element = document.getElementById(id); + if (element) { + if (attribute) + element.setAttribute(attribute, chrome.i18n.getMessage(msg)); + else + element.innerText = chrome.i18n.getMessage(msg); } } /** -* Given the tag, find if the given attribute has __MSG_some__ message -* and replace it if there is. +* Same as i18nReplaceImpl but provided for convenience for elements that have +* the same id as the i18n message id. */ -function substituteMessagesForTagAttribute(tag, attribute) { - var elements = document.getElementsByTagName(tag); - if (!elements) - return; - - var message_format = "__MSG_([a-zA-Z0-9_@]+)__"; - for (i = 0; i < elements.length; i++) { - var attribute_value = elements[i].getAttribute(attribute); - if (!attribute_value) - return; - - var old_text = attribute_value.match(message_format); - if (!old_text) - continue; - - elements[i].setAttribute( - attribute, chrome.i18n.getMessage(old_text[1])); - } -}
\ No newline at end of file +function i18nReplace(msg) { + i18nReplaceImpl(msg, msg, ''); +} diff --git a/chrome/test/data/extensions/subscribe_page_action/options.html b/chrome/test/data/extensions/subscribe_page_action/options.html index 2366d49..38f13f3 100644 --- a/chrome/test/data/extensions/subscribe_page_action/options.html +++ b/chrome/test/data/extensions/subscribe_page_action/options.html @@ -100,6 +100,10 @@ body>* { padding-right: 10px; } +.urlAssist { + padding-left: 30px; +} + .status { background-color: #FFF18A; } @@ -120,12 +124,6 @@ function main() { document.title = chrome.i18n.getMessage("rss_subscription_edit_dialog_title"); - substituteMessagesForTag("td"); - substituteMessagesForTag("div"); - substituteMessagesForTag("button"); - - substituteMessagesForTagAttribute("input", "value"); - // Make sure the dialog is not visible. document.getElementById('dialogBackground').style.display = "none"; @@ -230,7 +228,8 @@ function editReader(index) { var oldOption = readerListbox.options[editingIndex]; document.getElementById('urlText').value = oldOption.value; document.getElementById('descriptionText').value = - oldOption.text.replace(' (default)', ''); + oldOption.text.replace( + ' ' + chrome.i18n.getMessage("rss_subscription_default"), ''); editingDefault = isDefaultReader(oldOption.value); } @@ -329,18 +328,34 @@ function save() { main(); } +function init() { + i18nReplace('rss_subscription_options'); + i18nReplaceImpl('addReader', 'rss_subscription_add_reader'); + i18nReplaceImpl('editReader', 'rss_subscription_edit_reader'); + i18nReplaceImpl('removeReader', 'rss_subscription_remove_reader'); + i18nReplaceImpl('setDefault', 'rss_subscription_make_default_reader'); + i18nReplaceImpl('resetList', 'rss_subscription_reset_list'); + i18nReplace('rss_subscription_always_use_default'); + i18nReplaceImpl('dialogHeader', 'rss_subscription_edit_dialog_title'); + i18nReplace('rss_subscription_feed_description'); + i18nReplace('rss_subscription_feed_url'); + i18nReplaceImpl('save', 'rss_subscription_save_button', 'value'); + i18nReplaceImpl('rss_subscription_close_button', + 'rss_subscription_close_button', 'value'); + main(); +} </script> </head> -<body onload="main()"> +<body onload="init()"> <table border="0"> <tr> <td valign="top" width="16"> <img src="feed-icon-16x16.png" /> </td> <td valign="middle"> - <strong>__MSG_rss_subscription_options__</strong> + <strong id="rss_subscription_options"></strong> </td> - <td> + <td colspan="2"> </td> </tr> <tr> @@ -349,23 +364,25 @@ function save() { onchange="onSelectionChanged()"></select> </td> <td valign="top"> - <button style="width:100%;" id="addReader" onclick="editReader(-1)"> - __MSG_rss_subscription_add_reader__</button><br /> - <button style="width:100%;" id="editReader" onclick="editReader(0)"> - __MSG_rss_subscription_edit_reader__</button><br /> - <button style="width:100%;" id="removeReader" onclick="removeReader()"> - __MSG_rss_subscription_remove_reader__</button><br /> - <button style="width:100%;" id="setDefault" onclick="setDefault()"> - __MSG_rss_subscription_make_default_reader__</button><br /> - <button style="width:100%;" id="resetList" onclick="resetList()"> - __MSG_rss_subscription_reset_list__</button><br /> + <button style="width:100%;" id="addReader" onclick="editReader(-1)" + ></button><br /> + <button style="width:100%;" id="editReader" onclick="editReader(0)" + ></button><br /> + <button style="width:100%;" id="removeReader" onclick="removeReader()" + ></button><br /> + <button style="width:100%;" id="setDefault" onclick="setDefault()" + ></button><br /> + <button style="width:100%;" id="resetList" onclick="resetList()" + ></button><br /> + </td> + <td style="width: 200px;"> </td> </tr> <tr> - <td colspan="3"> + <td colspan="4"> <input type="checkbox" id="alwaysUseDefault" value="alwaysUseDefault" onchange="toggleFeedPreview()" - >__MSG_rss_subscription_always_use_default__ + ><span id="rss_subscription_always_use_default"></span> </td> </tr> </table> @@ -374,9 +391,7 @@ function save() { <div id="dialogHBackground"> <div id="dialog"> - <div id="dialogHeader"> - __MSG_rss_subscription_edit_dialog_title__ - </div> + <div id="dialogHeader"></div> <div id="dialogBody"> @@ -385,36 +400,31 @@ function save() { </div> <div class="dialogRow"> - <div> - __MSG_rss_subscription_feed_description__ - </div> + <div id="rss_subscription_feed_description"></div> <div> <input type="text" id="descriptionText" onkeyup="validateInput()"> </div> </div> <div class="dialogRow"> - <div> - __MSG_rss_subscription_feed_url__ - </div> + <div id="rss_subscription_feed_url"></div> <div> <input type="text" id="urlText" onkeyup="validateInput()"> </div> </div> <div class="dialogRow"> - <div id="urlAssist"></div> + <div id="urlAssist" class="urlAssist"></div> </div> <div class="dialogRow" id="dialogContentFooter"> <div> <input type="button" id="save" - value="__MSG_rss_subscription_save_button__" onclick="save()"> </div> <div> <input type="button" - value="__MSG_rss_subscription_close_button__" + id="rss_subscription_close_button" onclick="hideDialog()"> </div> </div> diff --git a/chrome/test/data/extensions/subscribe_page_action/subscribe.html b/chrome/test/data/extensions/subscribe_page_action/subscribe.html index f4bccbc..028b03b 100644 --- a/chrome/test/data/extensions/subscribe_page_action/subscribe.html +++ b/chrome/test/data/extensions/subscribe_page_action/subscribe.html @@ -13,10 +13,14 @@ <script> function init() { document.title = - chrome.i18n.getMessage("rss_subscription_default_title"); + chrome.i18n.getMessage("rss_subscription_default_title"); + i18nReplace('rss_subscription_subscribe_using'); + i18nReplace('rss_subscription_subscribe_button'); + i18nReplace('rss_subscription_always_use'); + i18nReplace('rss_subscription_feed_preview'); + i18nReplaceImpl('feedUrl', 'rss_subscription_feed_link', ''); + main(); - substituteMessagesForTag("span"); - substituteMessagesForTag("button"); } </script> </head> @@ -37,15 +41,14 @@ <td align="right" valign="middle"> <div> <span style="white-space: nowrap" - >__MSG_rss_subscription_subscribe_using__</span> + id="rss_subscription_subscribe_using"></span> </div> </td> <td valign="top"> <div style="margin-left:2px"> <select id="readerDropdown" onChange="onSelectChanged()"></select> - <button onclick="navigate();"> - __MSG_rss_subscription_subscribe_button__ - </button><br /> + <button onclick="navigate();" + id="rss_subscription_subscribe_button"></button><br /> </div> </td> </tr> @@ -54,7 +57,7 @@ <td valign="top" colspan="2"> <span id="alwaysUseSpan" style="display:none"><input type="checkbox" id="alwaysUse" value="AlwaysUse" - >__MSG_rss_subscription_always_use__</span> + ><span id="rss_subscription_always_use"></span></span> </td> </tr> </table> @@ -66,10 +69,10 @@ <div class="splitter"> <span class="feedUrlSpan" id="feedUrlSpan"> <span class="feedUrl" - >[ <a id="feedUrl" class="feedUrl" + >[ <a id="feedUrl" class="feedUrl" target="_blank" title="The feed page currently being previewed." - >__MSG_rss_subscription_feed_link__</a> ]</span></span> - <span><b>__MSG_rss_subscription_feed_preview__</b></span> + ></a> ]</span></span> + <span><b id="rss_subscription_feed_preview"></b></span> </div> <div id="items"></div> </body> diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc index d1cd7d3..fb1ec65 100644 --- a/chrome/test/ui_test_utils.cc +++ b/chrome/test/ui_test_utils.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -259,6 +259,26 @@ class SimpleNotificationObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver); }; +class TabParentedNotificationObserver : public NotificationObserver { + public: + TabParentedNotificationObserver() { + registrar_.Add(this, NotificationType::TAB_PARENTED, + NotificationService::AllSources()); + ui_test_utils::RunMessageLoop(); + } + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + MessageLoopForUI::current()->Quit(); + } + + private: + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(TabParentedNotificationObserver); +}; + class LanguageDetectionNotificationObserver : public NotificationObserver { public: explicit LanguageDetectionNotificationObserver(TabContents* tab) { @@ -395,6 +415,10 @@ void WaitForNewTab(Browser* browser) { new_tab_observer(NotificationType::TAB_ADDED, browser); } +void WaitForTabParented() { + TabParentedNotificationObserver new_tab_observer; +} + void WaitForLoadStop(NavigationController* controller) { SimpleNotificationObserver<NavigationController> new_tab_observer(NotificationType::LOAD_STOP, controller); diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h index 74482b8..462a9ec 100644 --- a/chrome/test/ui_test_utils.h +++ b/chrome/test/ui_test_utils.h @@ -64,6 +64,9 @@ void WaitForNavigations(NavigationController* controller, // Waits for a new tab to be added to |browser|. void WaitForNewTab(Browser* browser); +// Waits for a tab to be parented. +void WaitForTabParented(); + // Waits for a load stop for the specified |controller|. void WaitForLoadStop(NavigationController* controller); |