| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/test/automation/dom_element_proxy.h" | 8 #include "chrome/test/automation/dom_element_proxy.h" |
| 9 #include "chrome/test/automation/javascript_execution_controller.h" | 9 #include "chrome/test/automation/javascript_execution_controller.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Asserts that |expected_text| matches all the text in this element. This |
| 17 // includes the value of textfields and inputs. |
| 18 void EnsureTextMatches( |
| 19 DOMElementProxyRef proxy, const std::string& expected_text) { |
| 20 std::string text; |
| 21 ASSERT_TRUE(proxy->GetText(&text)); |
| 22 ASSERT_EQ(expected_text, text); |
| 23 } |
| 24 |
| 25 // Asserts that |expected_html| matches the element's inner html. |
| 26 void EnsureInnerHTMLMatches( |
| 27 DOMElementProxyRef proxy, const std::string& expected_html) { |
| 28 std::string html; |
| 29 ASSERT_TRUE(proxy->GetInnerHTML(&html)); |
| 30 ASSERT_EQ(expected_html, html); |
| 31 } |
| 32 |
| 33 // Asserts that |expected_name| matches the element's name. |
| 34 void EnsureNameMatches( |
| 35 DOMElementProxyRef proxy, const std::string& expected_name) { |
| 36 std::string name; |
| 37 ASSERT_TRUE(proxy->GetName(&name)); |
| 38 ASSERT_EQ(expected_name, name); |
| 39 } |
| 40 |
| 41 // Asserts that |expected_value| eventually matches the element's value for |
| 42 // |attribute|. This function will block until the timeout is exceeded, in |
| 43 // which case it will fail, or until the two values match. |
| 44 void EnsureAttributeEventuallyMatches( |
| 45 DOMElementProxyRef proxy, |
| 46 const std::string& attribute, |
| 47 const std::string& new_value) { |
| 48 ASSERT_TRUE(proxy->is_valid()); |
| 49 if (!proxy->DoesAttributeEventuallyMatch(attribute, new_value)) |
| 50 FAIL() << "Executing or parsing JavaScript failed"; |
| 51 } |
| 52 |
| 16 // Tests the DOMAutomation framework for manipulating DOMElements within | 53 // Tests the DOMAutomation framework for manipulating DOMElements within |
| 17 // browser tests. | 54 // browser tests. |
| 18 class DOMAutomationTest : public InProcessBrowserTest { | 55 class DOMAutomationTest : public InProcessBrowserTest { |
| 19 public: | 56 public: |
| 20 DOMAutomationTest() { | 57 DOMAutomationTest() { |
| 21 EnableDOMAutomation(); | 58 EnableDOMAutomation(); |
| 22 JavaScriptExecutionController::set_timeout(30000); | 59 JavaScriptExecutionController::set_timeout(30000); |
| 23 } | 60 } |
| 24 | 61 |
| 25 GURL GetTestURL(const char* path) { | 62 GURL GetTestURL(const char* path) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 #endif | 76 #endif |
| 40 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, MAYBE_FindByXPath) { | 77 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, MAYBE_FindByXPath) { |
| 41 ASSERT_TRUE(test_server()->Start()); | 78 ASSERT_TRUE(test_server()->Start()); |
| 42 ui_test_utils::NavigateToURL(browser(), | 79 ui_test_utils::NavigateToURL(browser(), |
| 43 GetTestURL("find_elements/test.html")); | 80 GetTestURL("find_elements/test.html")); |
| 44 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 81 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 45 | 82 |
| 46 // Find first element. | 83 // Find first element. |
| 47 DOMElementProxyRef first_div = main_doc->FindElement(By::XPath("//div")); | 84 DOMElementProxyRef first_div = main_doc->FindElement(By::XPath("//div")); |
| 48 ASSERT_TRUE(first_div); | 85 ASSERT_TRUE(first_div); |
| 49 ASSERT_NO_FATAL_FAILURE(first_div->EnsureNameMatches("0")); | 86 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches(first_div, "0")); |
| 50 | 87 |
| 51 // Find many elements. | 88 // Find many elements. |
| 52 std::vector<DOMElementProxyRef> elements; | 89 std::vector<DOMElementProxyRef> elements; |
| 53 ASSERT_TRUE(main_doc->FindElements(By::XPath("//div"), &elements)); | 90 ASSERT_TRUE(main_doc->FindElements(By::XPath("//div"), &elements)); |
| 54 ASSERT_EQ(2u, elements.size()); | 91 ASSERT_EQ(2u, elements.size()); |
| 55 for (size_t i = 0; i < elements.size(); i++) { | 92 for (size_t i = 0; i < elements.size(); i++) { |
| 56 ASSERT_NO_FATAL_FAILURE(elements[i]->EnsureNameMatches( | 93 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches( |
| 57 base::UintToString(i))); | 94 elements[i], base::UintToString(i))); |
| 58 } | 95 } |
| 59 | 96 |
| 60 // Find 0 elements. | 97 // Find 0 elements. |
| 61 ASSERT_FALSE(main_doc->FindElement(By::XPath("//nosuchtag"))); | 98 ASSERT_FALSE(main_doc->FindElement(By::XPath("//nosuchtag"))); |
| 62 elements.clear(); | 99 elements.clear(); |
| 63 ASSERT_TRUE(main_doc->FindElements(By::XPath("//nosuchtag"), &elements)); | 100 ASSERT_TRUE(main_doc->FindElements(By::XPath("//nosuchtag"), &elements)); |
| 64 elements.clear(); | 101 elements.clear(); |
| 65 ASSERT_EQ(0u, elements.size()); | 102 ASSERT_EQ(0u, elements.size()); |
| 66 | 103 |
| 67 // Find with invalid xpath. | 104 // Find with invalid xpath. |
| 68 ASSERT_FALSE(main_doc->FindElement(By::XPath("'invalid'"))); | 105 ASSERT_FALSE(main_doc->FindElement(By::XPath("'invalid'"))); |
| 69 ASSERT_FALSE(main_doc->FindElement(By::XPath(" / / "))); | 106 ASSERT_FALSE(main_doc->FindElement(By::XPath(" / / "))); |
| 70 ASSERT_FALSE(main_doc->FindElements(By::XPath("'invalid'"), &elements)); | 107 ASSERT_FALSE(main_doc->FindElements(By::XPath("'invalid'"), &elements)); |
| 71 ASSERT_FALSE(main_doc->FindElements(By::XPath(" / / "), &elements)); | 108 ASSERT_FALSE(main_doc->FindElements(By::XPath(" / / "), &elements)); |
| 72 | 109 |
| 73 // Find nested elements. | 110 // Find nested elements. |
| 74 int nested_count = 0; | 111 int nested_count = 0; |
| 75 std::string span_name; | 112 std::string span_name; |
| 76 DOMElementProxyRef node = main_doc->FindElement(By::XPath("/html/body/span")); | 113 DOMElementProxyRef node = main_doc->FindElement(By::XPath("/html/body/span")); |
| 77 while (node) { | 114 while (node) { |
| 78 nested_count++; | 115 nested_count++; |
| 79 span_name.append("span"); | 116 span_name.append("span"); |
| 80 ASSERT_NO_FATAL_FAILURE(node->EnsureNameMatches(span_name)); | 117 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches(node, span_name)); |
| 81 node = node->FindElement(By::XPath("./span")); | 118 node = node->FindElement(By::XPath("./span")); |
| 82 } | 119 } |
| 83 ASSERT_EQ(3, nested_count); | 120 ASSERT_EQ(3, nested_count); |
| 84 } | 121 } |
| 85 | 122 |
| 86 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, FindBySelectors) { | 123 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, FindBySelectors) { |
| 87 ASSERT_TRUE(test_server()->Start()); | 124 ASSERT_TRUE(test_server()->Start()); |
| 88 ui_test_utils::NavigateToURL(browser(), | 125 ui_test_utils::NavigateToURL(browser(), |
| 89 GetTestURL("find_elements/test.html")); | 126 GetTestURL("find_elements/test.html")); |
| 90 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 127 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 91 | 128 |
| 92 // Find first element. | 129 // Find first element. |
| 93 DOMElementProxyRef first_myclass = | 130 DOMElementProxyRef first_myclass = |
| 94 main_doc->FindElement(By::Selectors(".myclass")); | 131 main_doc->FindElement(By::Selectors(".myclass")); |
| 95 ASSERT_TRUE(first_myclass); | 132 ASSERT_TRUE(first_myclass); |
| 96 ASSERT_NO_FATAL_FAILURE(first_myclass->EnsureNameMatches("0")); | 133 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches(first_myclass, "0")); |
| 97 | 134 |
| 98 // Find many elements. | 135 // Find many elements. |
| 99 std::vector<DOMElementProxyRef> elements; | 136 std::vector<DOMElementProxyRef> elements; |
| 100 ASSERT_TRUE(main_doc->FindElements(By::Selectors(".myclass"), &elements)); | 137 ASSERT_TRUE(main_doc->FindElements(By::Selectors(".myclass"), &elements)); |
| 101 ASSERT_EQ(2u, elements.size()); | 138 ASSERT_EQ(2u, elements.size()); |
| 102 for (size_t i = 0; i < elements.size(); i++) { | 139 for (size_t i = 0; i < elements.size(); i++) { |
| 103 ASSERT_NO_FATAL_FAILURE(elements[i]->EnsureNameMatches( | 140 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches( |
| 104 base::UintToString(i))); | 141 elements[i], base::UintToString(i))); |
| 105 } | 142 } |
| 106 | 143 |
| 107 // Find 0 elements. | 144 // Find 0 elements. |
| 108 ASSERT_FALSE(main_doc->FindElement(By::Selectors("#nosuchid"))); | 145 ASSERT_FALSE(main_doc->FindElement(By::Selectors("#nosuchid"))); |
| 109 elements.clear(); | 146 elements.clear(); |
| 110 ASSERT_TRUE(main_doc->FindElements(By::Selectors("#nosuchid"), &elements)); | 147 ASSERT_TRUE(main_doc->FindElements(By::Selectors("#nosuchid"), &elements)); |
| 111 ASSERT_EQ(0u, elements.size()); | 148 ASSERT_EQ(0u, elements.size()); |
| 112 | 149 |
| 113 // Find with invalid selectors. | 150 // Find with invalid selectors. |
| 114 ASSERT_FALSE(main_doc->FindElement(By::Selectors("1#2"))); | 151 ASSERT_FALSE(main_doc->FindElement(By::Selectors("1#2"))); |
| 115 ASSERT_FALSE(main_doc->FindElements(By::Selectors("1#2"), &elements)); | 152 ASSERT_FALSE(main_doc->FindElements(By::Selectors("1#2"), &elements)); |
| 116 | 153 |
| 117 // Find nested elements. | 154 // Find nested elements. |
| 118 int nested_count = 0; | 155 int nested_count = 0; |
| 119 std::string span_name; | 156 std::string span_name; |
| 120 DOMElementProxyRef node = main_doc->FindElement(By::Selectors("span")); | 157 DOMElementProxyRef node = main_doc->FindElement(By::Selectors("span")); |
| 121 while (node) { | 158 while (node) { |
| 122 nested_count++; | 159 nested_count++; |
| 123 span_name.append("span"); | 160 span_name.append("span"); |
| 124 ASSERT_NO_FATAL_FAILURE(node->EnsureNameMatches(span_name)); | 161 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches(node, span_name)); |
| 125 node = node->FindElement(By::Selectors("span")); | 162 node = node->FindElement(By::Selectors("span")); |
| 126 } | 163 } |
| 127 ASSERT_EQ(3, nested_count); | 164 ASSERT_EQ(3, nested_count); |
| 128 } | 165 } |
| 129 | 166 |
| 130 #if defined(OS_WIN) | 167 #if defined(OS_WIN) |
| 131 // http://crbug.com/72745 | 168 // http://crbug.com/72745 |
| 132 #define MAYBE_FindByText FLAKY_FindByText | 169 #define MAYBE_FindByText FLAKY_FindByText |
| 133 #else | 170 #else |
| 134 #define MAYBE_FindByText FindByText | 171 #define MAYBE_FindByText FindByText |
| 135 #endif | 172 #endif |
| 136 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, MAYBE_FindByText) { | 173 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, MAYBE_FindByText) { |
| 137 ASSERT_TRUE(test_server()->Start()); | 174 ASSERT_TRUE(test_server()->Start()); |
| 138 ui_test_utils::NavigateToURL(browser(), | 175 ui_test_utils::NavigateToURL(browser(), |
| 139 GetTestURL("find_elements/test.html")); | 176 GetTestURL("find_elements/test.html")); |
| 140 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 177 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 141 | 178 |
| 142 // Find first element. | 179 // Find first element. |
| 143 DOMElementProxyRef first_text = main_doc->FindElement(By::Text("div_text")); | 180 DOMElementProxyRef first_text = main_doc->FindElement(By::Text("div_text")); |
| 144 ASSERT_TRUE(first_text); | 181 ASSERT_TRUE(first_text); |
| 145 ASSERT_NO_FATAL_FAILURE(first_text->EnsureNameMatches("0")); | 182 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches(first_text, "0")); |
| 146 | 183 |
| 147 // Find many elements. | 184 // Find many elements. |
| 148 std::vector<DOMElementProxyRef> elements; | 185 std::vector<DOMElementProxyRef> elements; |
| 149 ASSERT_TRUE(main_doc->FindElements(By::Text("div_text"), &elements)); | 186 ASSERT_TRUE(main_doc->FindElements(By::Text("div_text"), &elements)); |
| 150 ASSERT_EQ(2u, elements.size()); | 187 ASSERT_EQ(2u, elements.size()); |
| 151 for (size_t i = 0; i < elements.size(); i++) { | 188 for (size_t i = 0; i < elements.size(); i++) { |
| 152 ASSERT_NO_FATAL_FAILURE(elements[i]->EnsureNameMatches( | 189 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches( |
| 153 base::UintToString(i))); | 190 elements[i], base::UintToString(i))); |
| 154 } | 191 } |
| 155 | 192 |
| 156 // Find 0 elements. | 193 // Find 0 elements. |
| 157 ASSERT_FALSE(main_doc->FindElement(By::Text("nosuchtext"))); | 194 ASSERT_FALSE(main_doc->FindElement(By::Text("nosuchtext"))); |
| 158 elements.clear(); | 195 elements.clear(); |
| 159 ASSERT_TRUE(main_doc->FindElements(By::Text("nosuchtext"), &elements)); | 196 ASSERT_TRUE(main_doc->FindElements(By::Text("nosuchtext"), &elements)); |
| 160 ASSERT_EQ(0u, elements.size()); | 197 ASSERT_EQ(0u, elements.size()); |
| 161 | 198 |
| 162 // Find nested elements. | 199 // Find nested elements. |
| 163 int nested_count = 0; | 200 int nested_count = 0; |
| 164 std::string span_name; | 201 std::string span_name; |
| 165 DOMElementProxyRef node = main_doc->FindElement(By::Text("span_text")); | 202 DOMElementProxyRef node = main_doc->FindElement(By::Text("span_text")); |
| 166 while (node) { | 203 while (node) { |
| 167 nested_count++; | 204 nested_count++; |
| 168 span_name.append("span"); | 205 span_name.append("span"); |
| 169 ASSERT_NO_FATAL_FAILURE(node->EnsureNameMatches(span_name)); | 206 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches(node, span_name)); |
| 170 node = node->FindElement(By::Text("span_text")); | 207 node = node->FindElement(By::Text("span_text")); |
| 171 } | 208 } |
| 172 ASSERT_EQ(3, nested_count); | 209 ASSERT_EQ(3, nested_count); |
| 173 | 210 |
| 174 // Find only visible text. | 211 // Find only visible text. |
| 175 DOMElementProxyRef shown_td = main_doc->FindElement(By::Text("table_text")); | 212 DOMElementProxyRef shown_td = main_doc->FindElement(By::Text("table_text")); |
| 176 ASSERT_TRUE(shown_td); | 213 ASSERT_TRUE(shown_td); |
| 177 ASSERT_NO_FATAL_FAILURE(shown_td->EnsureNameMatches("shown")); | 214 ASSERT_NO_FATAL_FAILURE(EnsureNameMatches(shown_td, "shown")); |
| 178 | 215 |
| 179 // Find text in inputs. | 216 // Find text in inputs. |
| 180 ASSERT_TRUE(main_doc->FindElement(By::Text("textarea_text"))); | 217 ASSERT_TRUE(main_doc->FindElement(By::Text("textarea_text"))); |
| 181 ASSERT_TRUE(main_doc->FindElement(By::Text("input_text"))); | 218 ASSERT_TRUE(main_doc->FindElement(By::Text("input_text"))); |
| 182 } | 219 } |
| 183 | 220 |
| 184 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, WaitFor1VisibleElement) { | 221 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, WaitFor1VisibleElement) { |
| 185 ASSERT_TRUE(test_server()->Start()); | 222 ASSERT_TRUE(test_server()->Start()); |
| 186 ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); | 223 ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); |
| 187 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 224 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 188 | 225 |
| 189 DOMElementProxyRef div = | 226 DOMElementProxyRef div = |
| 190 main_doc->WaitFor1VisibleElement(By::Selectors("div")); | 227 main_doc->WaitFor1VisibleElement(By::Selectors("div")); |
| 191 ASSERT_TRUE(div.get()); | 228 ASSERT_TRUE(div.get()); |
| 192 ASSERT_NO_FATAL_FAILURE(div->EnsureInnerHTMLMatches("div_inner")); | 229 ASSERT_NO_FATAL_FAILURE(EnsureInnerHTMLMatches(div, "div_inner")); |
| 193 } | 230 } |
| 194 | 231 |
| 195 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, WaitForElementsToDisappear) { | 232 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, WaitForElementsToDisappear) { |
| 196 ASSERT_TRUE(test_server()->Start()); | 233 ASSERT_TRUE(test_server()->Start()); |
| 197 ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); | 234 ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); |
| 198 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 235 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 199 | 236 |
| 200 ASSERT_TRUE(main_doc->WaitForElementsToDisappear(By::Selectors("img"))); | 237 ASSERT_TRUE(main_doc->WaitForElementsToDisappear(By::Selectors("img"))); |
| 201 std::vector<DOMElementProxyRef> img_elements; | 238 std::vector<DOMElementProxyRef> img_elements; |
| 202 ASSERT_TRUE(main_doc->FindElements(By::Selectors("img"), &img_elements)); | 239 ASSERT_TRUE(main_doc->FindElements(By::Selectors("img"), &img_elements)); |
| 203 ASSERT_EQ(0u, img_elements.size()); | 240 ASSERT_EQ(0u, img_elements.size()); |
| 204 } | 241 } |
| 205 | 242 |
| 206 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, EnsureAttributeEventuallyMatches) { | 243 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, EnsureAttributeEventuallyMatches) { |
| 207 ASSERT_TRUE(test_server()->Start()); | 244 ASSERT_TRUE(test_server()->Start()); |
| 208 ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); | 245 ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); |
| 209 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 246 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 210 | 247 |
| 211 DOMElementProxyRef anchor = main_doc->FindElement(By::Selectors("a")); | 248 DOMElementProxyRef anchor = main_doc->FindElement(By::Selectors("a")); |
| 212 ASSERT_TRUE(anchor.get()); | 249 ASSERT_TRUE(anchor.get()); |
| 213 ASSERT_NO_FATAL_FAILURE(anchor->EnsureAttributeEventuallyMatches( | 250 ASSERT_NO_FATAL_FAILURE(EnsureAttributeEventuallyMatches( |
| 214 "href", "http://www.google.com")); | 251 anchor, "href", "http://www.google.com")); |
| 215 } | 252 } |
| 216 | 253 |
| 217 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, Frames) { | 254 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, Frames) { |
| 218 ASSERT_TRUE(test_server()->Start()); | 255 ASSERT_TRUE(test_server()->Start()); |
| 219 ui_test_utils::NavigateToURL(browser(), GetTestURL("frames/test.html")); | 256 ui_test_utils::NavigateToURL(browser(), GetTestURL("frames/test.html")); |
| 220 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 257 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 221 | 258 |
| 222 // Get both frame elements. | 259 // Get both frame elements. |
| 223 std::vector<DOMElementProxyRef> frame_elements; | 260 std::vector<DOMElementProxyRef> frame_elements; |
| 224 ASSERT_TRUE(main_doc->FindElements(By::XPath("//frame"), &frame_elements)); | 261 ASSERT_TRUE(main_doc->FindElements(By::XPath("//frame"), &frame_elements)); |
| 225 ASSERT_EQ(2u, frame_elements.size()); | 262 ASSERT_EQ(2u, frame_elements.size()); |
| 226 | 263 |
| 227 // Get both frames, checking their contents are correct. | 264 // Get both frames, checking their contents are correct. |
| 228 DOMElementProxyRef frame1 = frame_elements[0]->GetContentDocument(); | 265 DOMElementProxyRef frame1 = frame_elements[0]->GetContentDocument(); |
| 229 DOMElementProxyRef frame2 = frame_elements[1]->GetContentDocument(); | 266 DOMElementProxyRef frame2 = frame_elements[1]->GetContentDocument(); |
| 230 ASSERT_TRUE(frame1 && frame2); | 267 ASSERT_TRUE(frame1 && frame2); |
| 231 DOMElementProxyRef frame_div = | 268 DOMElementProxyRef frame_div = |
| 232 frame1->FindElement(By::XPath("/html/body/div")); | 269 frame1->FindElement(By::XPath("/html/body/div")); |
| 233 ASSERT_TRUE(frame_div); | 270 ASSERT_TRUE(frame_div); |
| 234 ASSERT_NO_FATAL_FAILURE(frame_div->EnsureInnerHTMLMatches("frame 1")); | 271 ASSERT_NO_FATAL_FAILURE(EnsureInnerHTMLMatches(frame_div, "frame 1")); |
| 235 frame_div = frame2->FindElement(By::XPath("/html/body/div")); | 272 frame_div = frame2->FindElement(By::XPath("/html/body/div")); |
| 236 ASSERT_TRUE(frame_div); | 273 ASSERT_TRUE(frame_div); |
| 237 ASSERT_NO_FATAL_FAILURE(frame_div->EnsureInnerHTMLMatches("frame 2")); | 274 ASSERT_NO_FATAL_FAILURE(EnsureInnerHTMLMatches(frame_div, "frame 2")); |
| 238 | 275 |
| 239 // Get both inner iframes, checking their contents are correct. | 276 // Get both inner iframes, checking their contents are correct. |
| 240 DOMElementProxyRef iframe1 = | 277 DOMElementProxyRef iframe1 = |
| 241 frame1->GetDocumentFromFrame("0"); | 278 frame1->GetDocumentFromFrame("0"); |
| 242 DOMElementProxyRef iframe2 = | 279 DOMElementProxyRef iframe2 = |
| 243 frame2->GetDocumentFromFrame("0"); | 280 frame2->GetDocumentFromFrame("0"); |
| 244 ASSERT_TRUE(iframe1 && iframe2); | 281 ASSERT_TRUE(iframe1 && iframe2); |
| 245 frame_div = iframe1->FindElement(By::XPath("/html/body/div")); | 282 frame_div = iframe1->FindElement(By::XPath("/html/body/div")); |
| 246 ASSERT_TRUE(frame_div); | 283 ASSERT_TRUE(frame_div); |
| 247 ASSERT_NO_FATAL_FAILURE(frame_div->EnsureInnerHTMLMatches("iframe 1")); | 284 ASSERT_NO_FATAL_FAILURE(EnsureInnerHTMLMatches(frame_div, "iframe 1")); |
| 248 frame_div = iframe2->FindElement(By::XPath("/html/body/div")); | 285 frame_div = iframe2->FindElement(By::XPath("/html/body/div")); |
| 249 ASSERT_TRUE(frame_div); | 286 ASSERT_TRUE(frame_div); |
| 250 ASSERT_NO_FATAL_FAILURE(frame_div->EnsureInnerHTMLMatches("iframe 2")); | 287 ASSERT_NO_FATAL_FAILURE(EnsureInnerHTMLMatches(frame_div, "iframe 2")); |
| 251 | 288 |
| 252 // Get nested frame. | 289 // Get nested frame. |
| 253 ASSERT_EQ(iframe1.get(), main_doc->GetDocumentFromFrame("0", "0").get()); | 290 ASSERT_EQ(iframe1.get(), main_doc->GetDocumentFromFrame("0", "0").get()); |
| 254 ASSERT_EQ(iframe2.get(), main_doc->GetDocumentFromFrame("1", "0").get()); | 291 ASSERT_EQ(iframe2.get(), main_doc->GetDocumentFromFrame("1", "0").get()); |
| 255 } | 292 } |
| 256 | 293 |
| 257 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, Events) { | 294 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, Events) { |
| 258 ASSERT_TRUE(test_server()->Start()); | 295 ASSERT_TRUE(test_server()->Start()); |
| 259 ui_test_utils::NavigateToURL(browser(), GetTestURL("events/test.html")); | 296 ui_test_utils::NavigateToURL(browser(), GetTestURL("events/test.html")); |
| 260 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 297 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 261 | 298 |
| 262 // Click link and make sure text changes. | 299 // Click link and make sure text changes. |
| 263 DOMElementProxyRef link = main_doc->FindElement(By::Selectors("a")); | 300 DOMElementProxyRef link = main_doc->FindElement(By::Selectors("a")); |
| 264 ASSERT_TRUE(link && link->Click()); | 301 ASSERT_TRUE(link && link->Click()); |
| 265 ASSERT_NO_FATAL_FAILURE(link->EnsureTextMatches("clicked")); | 302 ASSERT_NO_FATAL_FAILURE(EnsureTextMatches(link, "clicked")); |
| 266 | 303 |
| 267 // Click input button and make sure textfield changes. | 304 // Click input button and make sure textfield changes. |
| 268 DOMElementProxyRef button = main_doc->FindElement(By::Selectors("#button")); | 305 DOMElementProxyRef button = main_doc->FindElement(By::Selectors("#button")); |
| 269 DOMElementProxyRef textfield = | 306 DOMElementProxyRef textfield = |
| 270 main_doc->FindElement(By::Selectors("#textfield")); | 307 main_doc->FindElement(By::Selectors("#textfield")); |
| 271 ASSERT_TRUE(textfield && button && button->Click()); | 308 ASSERT_TRUE(textfield && button && button->Click()); |
| 272 ASSERT_NO_FATAL_FAILURE(textfield->EnsureTextMatches("clicked")); | 309 ASSERT_NO_FATAL_FAILURE(EnsureTextMatches(textfield, "clicked")); |
| 273 | 310 |
| 274 // Type in the textfield. | 311 // Type in the textfield. |
| 275 ASSERT_TRUE(textfield->SetText("test")); | 312 ASSERT_TRUE(textfield->SetText("test")); |
| 276 ASSERT_NO_FATAL_FAILURE(textfield->EnsureTextMatches("test")); | 313 ASSERT_NO_FATAL_FAILURE(EnsureTextMatches(textfield, "test")); |
| 277 | 314 |
| 278 // Type in the textarea. | 315 // Type in the textarea. |
| 279 DOMElementProxyRef textarea = | 316 DOMElementProxyRef textarea = |
| 280 main_doc->FindElement(By::Selectors("textarea")); | 317 main_doc->FindElement(By::Selectors("textarea")); |
| 281 ASSERT_TRUE(textarea && textarea->Type("test")); | 318 ASSERT_TRUE(textarea && textarea->Type("test")); |
| 282 ASSERT_NO_FATAL_FAILURE(textarea->EnsureTextMatches("textareatest")); | 319 ASSERT_NO_FATAL_FAILURE(EnsureTextMatches(textarea, "textareatest")); |
| 283 } | 320 } |
| 284 | 321 |
| 285 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, StringEscape) { | 322 IN_PROC_BROWSER_TEST_F(DOMAutomationTest, StringEscape) { |
| 286 ASSERT_TRUE(test_server()->Start()); | 323 ASSERT_TRUE(test_server()->Start()); |
| 287 ui_test_utils::NavigateToURL(browser(), | 324 ui_test_utils::NavigateToURL(browser(), |
| 288 GetTestURL("string_escape/test.html")); | 325 GetTestURL("string_escape/test.html")); |
| 289 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); | 326 DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); |
| 290 | 327 |
| 291 DOMElementProxyRef textarea = | 328 DOMElementProxyRef textarea = |
| 292 main_doc->FindElement(By::Selectors("textarea")); | 329 main_doc->FindElement(By::Selectors("textarea")); |
| 293 ASSERT_TRUE(textarea); | 330 ASSERT_TRUE(textarea); |
| 294 ASSERT_NO_FATAL_FAILURE(textarea->EnsureTextMatches(WideToUTF8(L"\u00FF"))); | 331 ASSERT_NO_FATAL_FAILURE(EnsureTextMatches(textarea, WideToUTF8(L"\u00FF"))); |
| 295 | 332 |
| 296 const wchar_t* set_and_expect_strings[] = { | 333 const wchar_t* set_and_expect_strings[] = { |
| 297 L"\u00FF and \u00FF", | 334 L"\u00FF and \u00FF", |
| 298 L"\n \t \\", | 335 L"\n \t \\", |
| 299 L"' \"" | 336 L"' \"" |
| 300 }; | 337 }; |
| 301 for (size_t i = 0; i < 3; i++) { | 338 for (size_t i = 0; i < 3; i++) { |
| 302 ASSERT_TRUE(textarea->SetText(WideToUTF8(set_and_expect_strings[i]))); | 339 ASSERT_TRUE(textarea->SetText(WideToUTF8(set_and_expect_strings[i]))); |
| 303 ASSERT_NO_FATAL_FAILURE(textarea->EnsureTextMatches( | 340 ASSERT_NO_FATAL_FAILURE(EnsureTextMatches( |
| 304 WideToUTF8(set_and_expect_strings[i]))); | 341 textarea, WideToUTF8(set_and_expect_strings[i]))); |
| 305 } | 342 } |
| 306 } | 343 } |
| 307 | 344 |
| 308 } // namespace | 345 } // namespace |
| OLD | NEW |