| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import pyauto_functional # Must be imported before pyauto | |
| 7 import pyauto | |
| 8 import test_utils | |
| 9 | |
| 10 | |
| 11 class SyncTest(pyauto.PyUITest): | |
| 12 """Tests for sync.""" | |
| 13 | |
| 14 def testSignInToSync(self): | |
| 15 """Sign in to sync.""" | |
| 16 new_timeout = pyauto.PyUITest.ActionTimeoutChanger(self, | |
| 17 60 * 1000) # 1 min. | |
| 18 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') | |
| 19 | |
| 20 def testDisableAndEnableDatatypes(self): | |
| 21 """Sign in, disable and then enable sync for multiple sync datatypes.""" | |
| 22 new_timeout = pyauto.PyUITest.ActionTimeoutChanger(self, | |
| 23 2 * 60 * 1000) # 2 min. | |
| 24 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') | |
| 25 self.assertTrue(self.DisableSyncForDatatypes(['Apps', 'Autofill', | |
| 26 'Bookmarks', 'Extensions', 'Preferences', 'Themes'])) | |
| 27 self.assertFalse('Apps' in self.GetSyncInfo()['synced datatypes']) | |
| 28 self.assertFalse('Autofill' in self.GetSyncInfo()['synced datatypes']) | |
| 29 self.assertFalse('Bookmarks' in self.GetSyncInfo()['synced datatypes']) | |
| 30 self.assertFalse('Extensions' in self.GetSyncInfo()['synced datatypes']) | |
| 31 self.assertFalse('Preferences' in self.GetSyncInfo()['synced datatypes']) | |
| 32 self.assertFalse('Themes' in self.GetSyncInfo()['synced datatypes']) | |
| 33 self.assertTrue(self.EnableSyncForDatatypes(['Apps', 'Autofill', | |
| 34 'Bookmarks', 'Extensions', 'Preferences','Themes'])) | |
| 35 self.assertTrue(self.DisableSyncForDatatypes(['Passwords'])) | |
| 36 self.assertTrue('Apps' in self.GetSyncInfo()['synced datatypes']) | |
| 37 self.assertTrue('Autofill' in self.GetSyncInfo()['synced datatypes']) | |
| 38 self.assertTrue('Bookmarks' in self.GetSyncInfo()['synced datatypes']) | |
| 39 self.assertTrue('Extensions' in self.GetSyncInfo()['synced datatypes']) | |
| 40 self.assertTrue('Preferences' in self.GetSyncInfo()['synced datatypes']) | |
| 41 self.assertTrue('Themes' in self.GetSyncInfo()['synced datatypes']) | |
| 42 self.assertFalse('Passwords' in self.GetSyncInfo()['synced datatypes']) | |
| 43 | |
| 44 def testRestartBrowser(self): | |
| 45 """Sign in to sync and restart the browser.""" | |
| 46 new_timeout = pyauto.PyUITest.ActionTimeoutChanger(self, | |
| 47 2 * 60 * 1000) # 2 min. | |
| 48 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') | |
| 49 self.RestartBrowser(clear_profile=False) | |
| 50 self.assertTrue(self.AwaitSyncRestart()) | |
| 51 self.assertTrue(self.GetSyncInfo()['last synced'] == 'Just now') | |
| 52 self.assertTrue(self.GetSyncInfo()['updates received'] == 0) | |
| 53 | |
| 54 def testPersonalStuffSyncSection(self): | |
| 55 """Verify the Sync section in Preferences before and after sync.""" | |
| 56 creds = self.GetPrivateInfo()['test_google_account'] | |
| 57 username = creds['username'] | |
| 58 password = creds['password'] | |
| 59 default_text = 'Keep everything synced or choose what data to sync' | |
| 60 set_up_button = 'Set Up Sync' | |
| 61 customize_button = 'Customize' | |
| 62 stop_button = 'Stop Sync' | |
| 63 signed_in_text = 'Google Dashboard' | |
| 64 chrome_settings_url = 'chrome://settings-frame' | |
| 65 new_timeout = pyauto.PyUITest.ActionTimeoutChanger(self, | |
| 66 2 * 60 * 1000) # 2 min. | |
| 67 self.AppendTab(pyauto.GURL(chrome_settings_url)) | |
| 68 self.assertTrue(self.WaitUntil( | |
| 69 lambda: self.FindInPage(default_text, tab_index=1)['match_count'], | |
| 70 expect_retval=1), | |
| 71 'No default sync text.') | |
| 72 self.assertTrue(self.WaitUntil( | |
| 73 lambda: self.FindInPage(set_up_button, tab_index=1)['match_count'], | |
| 74 expect_retval=1), | |
| 75 'No set up sync button.') | |
| 76 | |
| 77 self.assertTrue(self.SignInToSync(username, password)) | |
| 78 self.ReloadTab(1) | |
| 79 self.assertTrue(self.WaitUntil( | |
| 80 lambda: self.FindInPage(username, tab_index=1)['match_count'], | |
| 81 expect_retval=1), | |
| 82 'No sync user account information.') | |
| 83 self.assertTrue(self.WaitUntil( | |
| 84 lambda: self.FindInPage(signed_in_text, tab_index=1)['match_count'], | |
| 85 expect_retval=1), | |
| 86 'No Google Dashboard information after signing in.') | |
| 87 self.assertTrue(self.WaitUntil( | |
| 88 lambda: self.FindInPage(stop_button, tab_index=1)['match_count'], | |
| 89 expect_retval=1), | |
| 90 'No stop sync button.') | |
| 91 self.assertTrue(self.WaitUntil( | |
| 92 lambda: self.FindInPage(customize_button, tab_index=1)['match_count'], | |
| 93 expect_retval=1), | |
| 94 'No customize sync button.') | |
| 95 | |
| 96 | |
| 97 class SyncIntegrationTest(pyauto.PyUITest): | |
| 98 """Test integration between sync and other components.""" | |
| 99 | |
| 100 def ExtraChromeFlags(self): | |
| 101 """Prepares the browser to launch with the specified extra Chrome flags. | |
| 102 | |
| 103 |ChromeFlagsForTestServer()| is invoked to create the flags list. | |
| 104 """ | |
| 105 return pyauto.PyUITest.ExtraChromeFlags(self) + \ | |
| 106 self.ChromeFlagsForSyncTestServer(**self._sync_server.ports) | |
| 107 | |
| 108 def setUp(self): | |
| 109 # LaunchPythonSyncServer() executes before pyauto.PyUITest.setUp() because | |
| 110 # the latter invokes ExtraChromeFlags() which requires the server's ports. | |
| 111 self._sync_server = self.StartSyncServer() | |
| 112 pyauto.PyUITest.setUp(self) | |
| 113 | |
| 114 def tearDown(self): | |
| 115 pyauto.PyUITest.tearDown(self) | |
| 116 self.StopSyncServer(self._sync_server) | |
| 117 | |
| 118 def testAddBookmarkAndVerifySync(self): | |
| 119 """Verify a bookmark syncs between two browsers. | |
| 120 | |
| 121 Integration tests between the bookmarks and sync features. A bookmark is | |
| 122 added to one instance of the browser, the bookmark is synced to the account, | |
| 123 a new instance of the browser is launched, the account is synced and the | |
| 124 bookmark info is synced on the new browser. | |
| 125 """ | |
| 126 # Launch a new instance of the browser with a clean profile (Browser 2) | |
| 127 browser2 = pyauto.ExtraBrowser( | |
| 128 self.ChromeFlagsForSyncTestServer(**self._sync_server.ports)) | |
| 129 | |
| 130 account_key = 'test_sync_account' | |
| 131 test_utils.SignInToSyncAndVerifyState(self, account_key) | |
| 132 self.AwaitSyncCycleCompletion() | |
| 133 | |
| 134 # Add a bookmark. | |
| 135 bookmarks = self.GetBookmarkModel() | |
| 136 bar_id = bookmarks.BookmarkBar()['id'] | |
| 137 name = 'Column test' | |
| 138 url = self.GetHttpURLForDataPath('columns.html') | |
| 139 self.NavigateToURL(url) | |
| 140 self.AddBookmarkURL(bar_id, 0, name, url) | |
| 141 | |
| 142 # Refresh the bookmarks in the first browser. | |
| 143 bookmarks = self.GetBookmarkModel() | |
| 144 | |
| 145 # Log into the account and sync the browser to the account. | |
| 146 test_utils.SignInToSyncAndVerifyState(browser2, account_key) | |
| 147 browser2.AwaitSyncCycleCompletion() | |
| 148 | |
| 149 # Verify browser 2 contains the bookmark. | |
| 150 browser2_bookmarks = browser2.GetBookmarkModel() | |
| 151 self.assertEqual(browser2_bookmarks.NodeCount(), bookmarks.NodeCount()) | |
| 152 bar_child = browser2_bookmarks.BookmarkBar()['children'][0] | |
| 153 self.assertEqual(bar_child['type'], 'url') | |
| 154 self.assertEqual(bar_child['name'], name) | |
| 155 self.assertTrue(url in bar_child['url']) | |
| 156 | |
| 157 if __name__ == '__main__': | |
| 158 pyauto_functional.Main() | |
| OLD | NEW |