~allanlesage/+junk/ust-reboot-refactor

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/tests/test_with_webbrowser.py

new test: download file for which an app is already installed on system.
Also move the download_image test to the DownloadWithBrowserSystemTest class.

Approved by Sergio Cazzolato, manually merged by Omer Akram.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from ubuntu_system_tests.helpers import file_system as fs
34
34
from ubuntu_system_tests.helpers import gallery
35
35
from ubuntu_system_tests.helpers import images
 
36
from ubuntu_system_tests.helpers import mediaplayer
36
37
from ubuntu_system_tests.helpers import messaging
37
38
from ubuntu_system_tests.helpers.messaging import (
38
39
    fixture_setup as messaging_fixtures
112
113
    def setUp(self):
113
114
        super().setUp()
114
115
 
115
 
    def get_download_notification(self):
116
 
        notifications = self.shell.get_notifications_list()
117
 
        return notifications.get_download_finished_notification()
118
 
 
119
116
    def ensure_browser_actually_loaded(self, unity_proxy):
120
117
        """Fail the test if the browser app doesn't get past loading.
121
118
 
237
234
        recent_urls = new_tab_page.get_top_sites_list().get_urls()
238
235
        self.assertCountEqual(recent_urls, expected_recent_urls)
239
236
 
240
 
    def test_download_image(self):
241
 
        """Test to download an image from internet an save it locally"""
242
 
        img = test_data.get('ubuntu_img')
243
 
 
244
 
        # check there are no files in download folder
245
 
        self.assertEqual(
246
 
            len(fs.recursive_files_in_dir(fs.DIR_HOME_CACHE_GALLERY)), 0)
247
 
 
248
 
        # Go to page with the picture to download
249
 
        self.browser.go_to_url(test_data.get('page3').entered_url)
250
 
        self.browser.wait_until_page_loaded(test_data.get('page3').actual_url)
251
 
 
252
 
        # Click on the picture
253
 
        webview = self.browser.get_current_webview()
254
 
        self.browser.pointing_device.move_to_object(webview)
255
 
        self.browser.pointing_device.move(self.browser.pointing_device.x,
256
 
                                          self.browser.pointing_device.y / 2)
257
 
        self.browser.pointing_device.click(press_duration=3)
258
 
 
259
 
        # Select to save the image
260
 
        save_image = self.browser.get_popover_foreground_dialog_item(
261
 
            'Save image')
262
 
        self.browser.pointing_device.click_object(save_image)
263
 
 
264
 
        # Choose open in application option
265
 
        options = self.browser.get_download_options_dialog()
266
 
        options.choose_application()
267
 
 
268
 
        # Pick the gallery to see the picture after it is downlaoded
269
 
        picker = self.browser.get_open_with_dialog()
270
 
        picker.pick_gallery()
271
 
 
272
 
        # Wait for download complete notification
273
 
        notification = self.get_download_notification()
274
 
 
275
 
        # The downlod has completed, get the file path of the downloaded file
276
 
        download_path = fs.recursive_files_in_dir(fs.DIR_HOME_CACHE_GALLERY)[0]
277
 
        # Validates the file is the same as the original
278
 
        actual_sha1 = fs.calculate_file_sha1(download_path)
279
 
        self.assertEqual(img.sha1, actual_sha1)
280
 
 
281
 
        # Validates the file downloaded is moved to Pictures when opened
282
 
        notification.open()
283
 
        downloaded_file = os.path.join(
284
 
            fs.DIR_HOME_PICTURES_IMPORTED, img.file_name)
285
 
        self.assertTrue(wait_until(os.path.isfile, downloaded_file))
286
 
 
287
 
        # Validate the gallery-app is displaying the downloaded image
288
 
        events_view = gallery.get_gallery_events_view()
289
 
        self.assertTrue(events_view.is_image_displayed(img.file_name))
290
 
 
291
 
        # check the displayed image matches the reference image
292
 
        self.assertTrue(
293
 
            images.image_files_equal(
294
 
                downloaded_file, REFERENCE_DOWNLOAD_IMAGE))
295
 
 
296
237
    def _assert_find_in_page_item_not_visible_in_drawer(self):
297
238
        """Open the drawer and ensure 'Find in page' item is not visible."""
298
239
        self.browser.open_drawer()
523
464
    def setUp(self):
524
465
        super().setUp()
525
466
 
 
467
    def get_download_notification(self):
 
468
        notifications = self.shell.get_notifications_list()
 
469
        return notifications.get_download_finished_notification()
 
470
 
526
471
    def test_cancel_ongoing_download(self):
527
472
        """
528
473
        1. Open webbrowser and type in a url for a file to download
552
497
            self.shell.is_indicator_item_hidden(TRANSFER_INDICATOR),
553
498
            Eventually(Equals(True)))
554
499
 
 
500
    def test_download_file_supported_by_currently_installed_apps(self):
 
501
        """
 
502
        1. Open web browser and open a url to a file, for which an associated
 
503
           app is already installed on the device
 
504
        2. Wait for the download prompt to appear and tap on
 
505
           'Choose application' and select 'Media Player' on the next screen
 
506
        3. Tap on 'Open' button in the 'Download Complete' dialog and ensure
 
507
           the newly downloaded file starts playing in the media player
 
508
        """
 
509
        self.browser.go_to_url(data.urls.download3.url)
 
510
 
 
511
        options = self.browser.get_download_options_dialog()
 
512
        options.choose_application()
 
513
 
 
514
        picker = self.browser.get_open_with_dialog()
 
515
        picker.pick_media_player()
 
516
 
 
517
        self.assertThat(
 
518
            self.shell.is_indicator_item_hidden(TRANSFER_INDICATOR),
 
519
            Eventually(Equals(False)))
 
520
 
 
521
        # Wait for download complete notification
 
522
        notification = self.get_download_notification()
 
523
        notification.open()
 
524
 
 
525
        player = mediaplayer.get_media_player_proxy().player
 
526
        self.assertTrue(player.playing)
 
527
 
 
528
    def test_download_image(self):
 
529
        """Test to download an image from internet an save it locally"""
 
530
        img = test_data.get('ubuntu_img')
 
531
 
 
532
        # check there are no files in download folder
 
533
        self.assertEqual(
 
534
            len(fs.recursive_files_in_dir(fs.DIR_HOME_CACHE_GALLERY)), 0)
 
535
 
 
536
        # Go to page with the picture to download
 
537
        self.browser.go_to_url(test_data.get('page3').entered_url)
 
538
        self.browser.wait_until_page_loaded(test_data.get('page3').actual_url)
 
539
 
 
540
        # Click on the picture
 
541
        webview = self.browser.get_current_webview()
 
542
        self.browser.pointing_device.move_to_object(webview)
 
543
        self.browser.pointing_device.move(self.browser.pointing_device.x,
 
544
                                          self.browser.pointing_device.y / 2)
 
545
        self.browser.pointing_device.click(press_duration=3)
 
546
 
 
547
        # Select to save the image
 
548
        save_image = self.browser.get_popover_foreground_dialog_item(
 
549
            'Save image')
 
550
        self.browser.pointing_device.click_object(save_image)
 
551
 
 
552
        # Choose open in application option
 
553
        options = self.browser.get_download_options_dialog()
 
554
        options.choose_application()
 
555
 
 
556
        # Pick the gallery to see the picture after it is downlaoded
 
557
        picker = self.browser.get_open_with_dialog()
 
558
        picker.pick_gallery()
 
559
 
 
560
        # Wait for download complete notification
 
561
        notification = self.get_download_notification()
 
562
 
 
563
        # The downlod has completed, get the file path of the downloaded file
 
564
        download_path = fs.recursive_files_in_dir(fs.DIR_HOME_CACHE_GALLERY)[0]
 
565
        # Validates the file is the same as the original
 
566
        actual_sha1 = fs.calculate_file_sha1(download_path)
 
567
        self.assertEqual(img.sha1, actual_sha1)
 
568
 
 
569
        # Validates the file downloaded is moved to Pictures when opened
 
570
        notification.open()
 
571
        downloaded_file = os.path.join(
 
572
            fs.DIR_HOME_PICTURES_IMPORTED, img.file_name)
 
573
        self.assertTrue(wait_until(os.path.isfile, downloaded_file))
 
574
 
 
575
        # Validate the gallery-app is displaying the downloaded image
 
576
        events_view = gallery.get_gallery_events_view()
 
577
        self.assertTrue(events_view.is_image_displayed(img.file_name))
 
578
 
 
579
        # check the displayed image matches the reference image
 
580
        self.assertTrue(
 
581
            images.image_files_equal(
 
582
                downloaded_file, REFERENCE_DOWNLOAD_IMAGE))
 
583
 
555
584
 
556
585
class DownloadsHistoryWithBrowserSystemTest(base_webbrowser.WebBrowserBase):
557
586