- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / backends / chrome / inspector_page_unittest.py
1 # Copyright 2013 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.unittest import tab_test_case
7
8
9 class InspectorPageTest(tab_test_case.TabTestCase):
10   def __init__(self, *args):
11     super(InspectorPageTest, self).__init__(*args)
12
13   def setUp(self):
14     super(InspectorPageTest, self).setUp()
15     self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
16
17   def testPageNavigateToNormalUrl(self):
18     self._tab.Navigate(self._browser.http_server.UrlOf('blank.html'))
19     self._tab.WaitForDocumentReadyStateToBeComplete()
20
21   def testCustomActionToNavigate(self):
22     self._tab.Navigate(
23       self._browser.http_server.UrlOf('page_with_link.html'))
24     self._tab.WaitForDocumentReadyStateToBeComplete()
25     self.assertEquals(
26         self._tab.EvaluateJavaScript('document.location.pathname;'),
27         '/page_with_link.html')
28
29     custom_action_called = [False]
30     def CustomAction():
31       custom_action_called[0] = True
32       self._tab.ExecuteJavaScript('document.getElementById("clickme").click();')
33
34     self._tab.PerformActionAndWaitForNavigate(CustomAction)
35
36     self.assertTrue(custom_action_called[0])
37     self.assertEquals(
38         self._tab.EvaluateJavaScript('document.location.pathname;'),
39         '/blank.html')
40
41   def testGetCookieByName(self):
42     self._tab.Navigate(
43       self._browser.http_server.UrlOf('blank.html'))
44     self._tab.WaitForDocumentReadyStateToBeComplete()
45     self._tab.ExecuteJavaScript('document.cookie="foo=bar"')
46     self.assertEquals(self._tab.GetCookieByName('foo'), 'bar')
47
48   def testScriptToEvaluateOnCommit(self):
49     self._tab.Navigate(
50       self._browser.http_server.UrlOf('blank.html'),
51       script_to_evaluate_on_commit='var foo = "bar";')
52     self._tab.WaitForDocumentReadyStateToBeComplete()
53     self.assertEquals(self._tab.EvaluateJavaScript('foo'), 'bar')