- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / click_element_unittest.py
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.
4
5 from telemetry.core import util
6 from telemetry.page.actions import click_element
7 from telemetry.page.actions import wait
8 from telemetry.unittest import tab_test_case
9
10 class ClickElementActionTest(tab_test_case.TabTestCase):
11   def testClickWithSelectorWaitForNavigation(self):
12     self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
13     self._tab.Navigate(
14       self._browser.http_server.UrlOf('page_with_link.html'))
15     self._tab.WaitForDocumentReadyStateToBeComplete()
16     self.assertEquals(
17         self._tab.EvaluateJavaScript('document.location.pathname;'),
18         '/page_with_link.html')
19
20     data = {'selector': 'a[id="clickme"]'}
21     i = click_element.ClickElementAction(data)
22     data = {'condition': 'href_change'}
23     j = wait.WaitAction(data)
24     j.RunAction(None, self._tab, i)
25
26     self.assertEquals(
27         self._tab.EvaluateJavaScript('document.location.pathname;'),
28         '/blank.html')
29
30   def testClickWithTextWaitForRefChange(self):
31     self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
32     self._tab.Navigate(
33       self._browser.http_server.UrlOf('page_with_link.html'))
34     self._tab.WaitForDocumentReadyStateToBeComplete()
35     self.assertEquals(
36         self._tab.EvaluateJavaScript('document.location.pathname;'),
37         '/page_with_link.html')
38
39     data = {'text': 'Click me'}
40     i = click_element.ClickElementAction(data)
41     data = {'condition': 'href_change'}
42     j = wait.WaitAction(data)
43     j.RunAction(None, self._tab, i)
44
45     self.assertEquals(
46         self._tab.EvaluateJavaScript('document.location.pathname;'),
47         '/blank.html')
48
49   def testClickWithXPathWaitForRefChange(self):
50     self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
51     self._tab.Navigate(
52       self._browser.http_server.UrlOf('page_with_link.html'))
53     self._tab.WaitForDocumentReadyStateToBeComplete()
54     self.assertEquals(
55         self._tab.EvaluateJavaScript('document.location.pathname;'),
56         '/page_with_link.html')
57
58     data = {'xpath': '//a[@id="clickme"]'}
59     i = click_element.ClickElementAction(data)
60     data = {'condition': 'href_change'}
61     j = wait.WaitAction(data)
62     j.RunAction(None, self._tab, i)
63
64     self.assertEquals(
65         self._tab.EvaluateJavaScript('document.location.pathname;'),
66         '/blank.html')