27
27
from webbrowser_app.tests import StartOpenRemotePageTestCaseBase
29
from ubuntuuitoolkit import ToolkitException
30
32
class TestNewTabViewLifetime(StartOpenRemotePageTestCaseBase):
32
34
def test_new_tab_view_destroyed_when_browsing(self):
33
if not self.main_window.wide:
35
new_tab_view = self.open_new_tab()
35
new_tab_view = self.open_new_tab(open_tabs_view=True)
36
36
self.main_window.go_to_url(self.base_url + "/test2")
37
37
new_tab_view.wait_until_destroyed()
39
39
def test_new_tab_view_destroyed_when_closing_tab(self):
40
if not self.main_window.wide:
42
new_tab_view = self.open_new_tab()
40
new_tab_view = self.open_new_tab(open_tabs_view=True)
43
41
if self.main_window.wide:
44
42
self.main_window.chrome.get_tabs_bar().close_tab(1)
52
50
def test_new_tab_view_is_shared_between_tabs(self):
54
if not self.main_window.wide:
56
new_tab_view = self.open_new_tab()
52
new_tab_view = self.open_new_tab(open_tabs_view=True)
57
53
# Open a second new tab
58
if not self.main_window.wide:
60
new_tab_view_2 = self.open_new_tab()
54
new_tab_view_2 = self.open_new_tab(open_tabs_view=True)
61
55
# Verify that they share the same NewTabView instance
62
56
self.assertThat(new_tab_view_2.id, Equals(new_tab_view.id))
63
57
# Close the second new tab, and verify that the NewTabView instance
123
117
self.main_window.go_to_url(self.base_url + "/test2")
124
118
new_private_tab_view.wait_until_destroyed()
125
119
# Open one new private tab
126
if not self.main_window.wide:
127
self.open_tabs_view()
128
new_private_tab_view = self.open_new_tab()
120
new_private_tab_view = self.open_new_tab(open_tabs_view=True)
129
121
# Open a second new private tab
130
if not self.main_window.wide:
131
self.open_tabs_view()
132
new_private_tab_view_2 = self.open_new_tab()
122
new_private_tab_view_2 = self.open_new_tab(open_tabs_view=True)
133
123
# Verify that they share the same NewPrivateTabView instance
134
124
self.assertThat(new_private_tab_view_2.id,
135
125
Equals(new_private_tab_view.id))
156
146
new_private_tab_view.wait_until_destroyed()
159
class TestNewTabViewContents(StartOpenRemotePageTestCaseBase):
149
class TestNewTabViewContentsBase(StartOpenRemotePageTestCaseBase):
162
152
self.create_temporary_profile()
163
153
self.populate_config()
164
154
self.populate_bookmarks()
165
super(TestNewTabViewContents, self).setUp()
166
if not self.main_window.wide:
167
self.open_tabs_view()
168
self.new_tab_view = self.open_new_tab()
155
super(TestNewTabViewContentsBase, self).setUp()
156
self.new_tab_view = self.open_new_tab(open_tabs_view=True)
170
158
def populate_config(self):
171
159
self.homepage = "http://test/test2"
233
229
self.new_tab_view.wait_until_destroyed()
234
230
self.main_window.wait_until_page_loaded(self.homepage)
236
def test_open_bookmark_when_collapsed(self):
232
def test_open_top_site(self):
233
top_sites = self.new_tab_view.get_top_sites_list()
234
self.assertThat(lambda: len(top_sites.get_delegates()),
235
Eventually(Equals(1)))
236
top_site = top_sites.get_delegates()[0]
238
self.pointing_device.click_object(top_site)
239
self.new_tab_view.wait_until_destroyed()
240
self.main_window.wait_until_page_loaded(url)
242
def test_open_bookmark(self):
237
243
bookmarks = self.new_tab_view.get_bookmarks_list()
238
self.assertThat(lambda: len(bookmarks.get_delegates()),
239
Eventually(Equals(4)))
240
244
bookmark = bookmarks.get_delegates()[1]
241
245
url = bookmark.url
242
246
self.pointing_device.click_object(bookmark)
396
400
folder_delegate)),
397
401
Eventually(Equals(4)))
399
def test_open_top_site(self):
400
top_sites = self.new_tab_view.get_top_sites_list()
401
self.assertThat(lambda: len(top_sites.get_delegates()),
402
Eventually(Equals(1)))
403
top_site = top_sites.get_delegates()[0]
405
self.pointing_device.click_object(top_site)
406
self.new_tab_view.wait_until_destroyed()
407
self.main_window.wait_until_page_loaded(url)
409
403
def test_remove_top_sites(self):
410
404
top_sites = self.new_tab_view.get_top_sites_list()
411
405
self.assertThat(lambda: len(top_sites.get_delegates()),
418
412
self.assertThat(lambda: len(top_sites.get_delegates()),
419
413
Eventually(Equals(0)))
420
414
self.assertThat(notopsites_label.visible, Eventually(Equals(True)))
417
class TestNewTabViewContentsWide(TestNewTabViewContentsBase):
420
super(TestNewTabViewContentsWide, self).setUp()
421
if not self.main_window.wide:
422
self.skipTest("Only on wide form factors")
424
def test_remove_bookmarks(self):
425
view = self.new_tab_view
426
bookmarks = view.get_bookmarks_list()
427
previous_count = len(bookmarks)
428
bookmarks[1].trigger_leading_action("leadingAction.delete",
429
bookmarks[1].wait_until_destroyed)
430
bookmarks = view.get_bookmarks_list()
431
self.assertThat(len(bookmarks), Equals(previous_count - 1))
432
previous_count = len(bookmarks)
434
# verify that trying to delete the homepage bookmark is not going to
435
# do anything because there is no delete action on the delegate
436
no_delete_action = False
438
bookmarks[0].trigger_leading_action("leadingAction.delete")
439
except ToolkitException:
440
no_delete_action = True
441
self.assertThat(no_delete_action, Equals(True))
442
self.assertThat(len(view.get_bookmarks_list()), Equals(previous_count))
444
def test_remove_top_sites(self):
445
view = self.new_tab_view
446
topsites = view.get_top_sites_list()
447
previous_count = len(topsites)
448
topsites[0].trigger_leading_action("leadingAction.delete",
449
topsites[0].wait_until_destroyed)
450
self.assertThat(len(view.get_top_sites_list()),
451
Equals(previous_count - 1))
453
def test_drag_bookmarks(self):
454
view = self.new_tab_view
455
folders = view.get_folders_list()
456
bookmarks = view.get_bookmarks_list()
457
previous_count = len(bookmarks)
458
bookmark = bookmarks[1]
459
title = bookmark.title
460
grip = bookmark.get_grip()
461
original_x = grip.globalRect.x
462
original_y = grip.globalRect.y
464
# Test that when hovering normal bookmarks item the grip appears
465
self.assertThat(grip.opacity, Equals(0))
466
self.pointing_device.move_to_object(bookmark)
467
self.assertThat(grip.opacity, Eventually(Equals(1.0)))
469
# Test that an item bounces back when dragged within the list itself
470
self.pointing_device.drag(original_x, original_y,
471
original_x, original_y + 200)
473
# Test that an item bounces back when dragged to the same folder
475
folder_cx = folder.globalRect.x + folder.width / 2
476
folder_cy = folder.globalRect.y + folder.height / 2
477
self.pointing_device.drag(original_x, original_y,
478
folder_cx, folder_cy)
480
self.assertThat(lambda: (grip.globalRect.x, grip.globalRect.y),
481
Eventually(Equals((original_x, original_y))))
483
# Test that dragging an item to another folder removes it from this one
484
# and adds it to the target folder
486
folder_cx = folder.globalRect.x + folder.width / 2
487
folder_cy = folder.globalRect.y + folder.height / 2
488
self.pointing_device.drag(original_x, original_y,
489
folder_cx, folder_cy)
491
self.assertThat(lambda: len(view.get_bookmarks_list()),
492
Eventually(NotEquals(previous_count)))
494
# Verify that the item has been added to the top of the target folder
495
self.pointing_device.click_object(folder)
496
self.assertThat(lambda: len(view.get_bookmarks_list()),
497
Eventually(Equals(2)))
498
self.assertThat(view.get_bookmarks_list()[0].title, Equals(title))