| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import copy | 6 import copy |
| 7 import os | 7 import os |
| 8 | 8 |
| 9 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
| 10 import pyauto | 10 import pyauto |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 actual_info[i][attribute])) | 372 actual_info[i][attribute])) |
| 373 | 373 |
| 374 def _InstallAndVerifySamplePackagedApp(self): | 374 def _InstallAndVerifySamplePackagedApp(self): |
| 375 """Installs a sample packaged app and verifies the install is successful. | 375 """Installs a sample packaged app and verifies the install is successful. |
| 376 | 376 |
| 377 Returns: | 377 Returns: |
| 378 The string ID of the installed app. | 378 The string ID of the installed app. |
| 379 """ | 379 """ |
| 380 app_crx_file = os.path.abspath(os.path.join( | 380 app_crx_file = os.path.abspath(os.path.join( |
| 381 self.DataDir(), 'pyauto_private', 'apps', 'countdown.crx')) | 381 self.DataDir(), 'pyauto_private', 'apps', 'countdown.crx')) |
| 382 installed_app_id = self.InstallApp(app_crx_file) | 382 return self.InstallExtension(app_crx_file) |
| 383 self.assertTrue(installed_app_id, msg='App install failed.') | |
| 384 return installed_app_id | |
| 385 | 383 |
| 386 def testGetAppsInNewProfile(self): | 384 def testGetAppsInNewProfile(self): |
| 387 """Ensures that the only app in a new profile is the Web Store app.""" | 385 """Ensures that the only app in a new profile is the Web Store app.""" |
| 388 app_info = self.GetNTPApps() | 386 app_info = self.GetNTPApps() |
| 389 self._VerifyAppInfo(app_info, self._EXPECTED_DEFAULT_APPS) | 387 self._VerifyAppInfo(app_info, self._EXPECTED_DEFAULT_APPS) |
| 390 | 388 |
| 391 def testGetAppsWhenInstallApp(self): | 389 def testGetAppsWhenInstallApp(self): |
| 392 """Ensures that an installed app is reflected in the app info in the NTP.""" | 390 """Ensures that an installed app is reflected in the app info in the NTP.""" |
| 393 self._InstallAndVerifySamplePackagedApp() | 391 self._InstallAndVerifySamplePackagedApp() |
| 394 app_info = self.GetNTPApps() | 392 app_info = self.GetNTPApps() |
| 395 expected_app_info = [ | 393 expected_app_info = [ |
| 396 { | 394 { |
| 397 u'title': u'Countdown' | 395 u'title': u'Countdown' |
| 398 } | 396 } |
| 399 ] | 397 ] |
| 400 expected_app_info.extend(self._EXPECTED_DEFAULT_APPS) | 398 expected_app_info.extend(self._EXPECTED_DEFAULT_APPS) |
| 401 self._VerifyAppInfo(app_info, expected_app_info) | 399 self._VerifyAppInfo(app_info, expected_app_info) |
| 402 | 400 |
| 403 def testGetAppsWhenInstallNonApps(self): | 401 def testGetAppsWhenInstallNonApps(self): |
| 404 """Ensures installed non-apps are not reflected in the NTP app info.""" | 402 """Ensures installed non-apps are not reflected in the NTP app info.""" |
| 405 # Install a regular extension and a theme. | 403 # Install a regular extension and a theme. |
| 406 ext_crx_file = os.path.abspath(os.path.join(self.DataDir(), 'extensions', | 404 ext_crx_file = os.path.abspath(os.path.join(self.DataDir(), 'extensions', |
| 407 'page_action.crx')) | 405 'page_action.crx')) |
| 408 self.assertTrue(self.InstallExtension(ext_crx_file, False), | 406 self.InstallExtension(ext_crx_file) |
| 409 msg='Extension install failed.') | |
| 410 theme_crx_file = os.path.abspath(os.path.join(self.DataDir(), 'extensions', | 407 theme_crx_file = os.path.abspath(os.path.join(self.DataDir(), 'extensions', |
| 411 'theme.crx')) | 408 'theme.crx')) |
| 412 self.assertTrue(self.SetTheme(theme_crx_file), msg='Theme install failed.') | 409 self.SetTheme(theme_crx_file) |
| 413 # Verify that no apps are listed on the NTP except for the Web Store. | 410 # Verify that no apps are listed on the NTP except for the Web Store. |
| 414 app_info = self.GetNTPApps() | 411 app_info = self.GetNTPApps() |
| 415 self._VerifyAppInfo(app_info, self._EXPECTED_DEFAULT_APPS) | 412 self._VerifyAppInfo(app_info, self._EXPECTED_DEFAULT_APPS) |
| 416 | 413 |
| 417 def testUninstallApp(self): | 414 def testUninstallApp(self): |
| 418 """Ensures that an uninstalled app is reflected in the NTP app info.""" | 415 """Ensures that an uninstalled app is reflected in the NTP app info.""" |
| 419 # First, install an app and verify that it exists in the NTP app info. | 416 # First, install an app and verify that it exists in the NTP app info. |
| 420 installed_app_id = self._InstallAndVerifySamplePackagedApp() | 417 installed_app_id = self._InstallAndVerifySamplePackagedApp() |
| 421 app_info = self.GetNTPApps() | 418 app_info = self.GetNTPApps() |
| 422 expected_app_info = [ | 419 expected_app_info = [ |
| 423 { | 420 { |
| 424 u'title': u'Countdown' | 421 u'title': u'Countdown' |
| 425 } | 422 } |
| 426 ] | 423 ] |
| 427 expected_app_info.extend(self._EXPECTED_DEFAULT_APPS) | 424 expected_app_info.extend(self._EXPECTED_DEFAULT_APPS) |
| 428 self._VerifyAppInfo(app_info, expected_app_info) | 425 self._VerifyAppInfo(app_info, expected_app_info) |
| 429 | 426 |
| 430 # Next, uninstall the app and verify that it is removed from the NTP. | 427 # Next, uninstall the app and verify that it is removed from the NTP. |
| 431 self.assertTrue(self.UninstallApp(installed_app_id), | 428 self.assertTrue(self.UninstallExtensionById(installed_app_id), |
| 432 msg='Call to UninstallApp() returned False.') | 429 msg='Call to UninstallExtensionById() returned False.') |
| 433 app_info = self.GetNTPApps() | 430 app_info = self.GetNTPApps() |
| 434 self._VerifyAppInfo(app_info, self._EXPECTED_DEFAULT_APPS) | 431 self._VerifyAppInfo(app_info, self._EXPECTED_DEFAULT_APPS) |
| 435 | 432 |
| 436 def testCannotUninstallWebStore(self): | 433 def testCannotUninstallWebStore(self): |
| 437 """Ensures that the WebStore app cannot be uninstalled.""" | 434 """Ensures that the WebStore app cannot be uninstalled.""" |
| 438 # Verify that the WebStore app is already installed in a fresh profile. | 435 # Verify that the WebStore app is already installed in a fresh profile. |
| 439 app_info = self.GetNTPApps() | 436 app_info = self.GetNTPApps() |
| 440 self._VerifyAppInfo(app_info, self._EXPECTED_DEFAULT_APPS) | 437 self._VerifyAppInfo(app_info, self._EXPECTED_DEFAULT_APPS) |
| 441 self.assertTrue(app_info and 'id' in app_info[0], | 438 self.assertTrue(app_info and 'id' in app_info[0], |
| 442 msg='Cannot identify ID of WebStore app.') | 439 msg='Cannot identify ID of WebStore app.') |
| 443 webstore_id = app_info[0]['id'] | 440 webstore_id = app_info[0]['id'] |
| 444 | 441 |
| 445 # Attempt to uninstall the WebStore app and verify that it still exists | 442 # Attempt to uninstall the WebStore app and verify that it still exists |
| 446 # in the App info of the NTP even after we try to uninstall it. | 443 # in the App info of the NTP even after we try to uninstall it. |
| 447 self.assertFalse(self.UninstallApp(webstore_id), | 444 self.assertFalse(self.UninstallExtensionById(webstore_id), |
| 448 msg='Call to UninstallApp() returned True.') | 445 msg='Call to UninstallExtensionById() returned True.') |
| 449 self._VerifyAppInfo(self.GetNTPApps(), self._EXPECTED_DEFAULT_APPS) | 446 self._VerifyAppInfo(self.GetNTPApps(), self._EXPECTED_DEFAULT_APPS) |
| 450 | 447 |
| 451 def testLaunchAppWithDefaultSettings(self): | 448 def testLaunchAppWithDefaultSettings(self): |
| 452 """Verifies that an app can be launched with the default settings.""" | 449 """Verifies that an app can be launched with the default settings.""" |
| 453 # Install an app. | 450 # Install an app. |
| 454 installed_app_id = self._InstallAndVerifySamplePackagedApp() | 451 installed_app_id = self._InstallAndVerifySamplePackagedApp() |
| 455 | 452 |
| 456 # Launch the app from the NTP. | 453 # Launch the app from the NTP. |
| 457 self.LaunchApp(installed_app_id) | 454 self.LaunchApp(installed_app_id) |
| 458 | 455 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 info = self.GetBrowserInfo() | 521 info = self.GetBrowserInfo() |
| 525 self.assertTrue(len(info['windows']) == 2, | 522 self.assertTrue(len(info['windows']) == 2, |
| 526 msg='A second window does not exist.') | 523 msg='A second window does not exist.') |
| 527 actual_tab_url = info['windows'][1]['tabs'][0]['url'] | 524 actual_tab_url = info['windows'][1]['tabs'][0]['url'] |
| 528 expected_app_url_start = 'chrome-extension://' + installed_app_id | 525 expected_app_url_start = 'chrome-extension://' + installed_app_id |
| 529 self.assertTrue(actual_tab_url.startswith(expected_app_url_start), | 526 self.assertTrue(actual_tab_url.startswith(expected_app_url_start), |
| 530 msg='The app was not launched in the new window.') | 527 msg='The app was not launched in the new window.') |
| 531 | 528 |
| 532 if __name__ == '__main__': | 529 if __name__ == '__main__': |
| 533 pyauto_functional.Main() | 530 pyauto_functional.Main() |
| OLD | NEW |