Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: chrome/test/data/webui/md_bookmarks/edit_dialog_test.js

Issue 2780223004: MD Bookmarks: Implement dialog to add new folders/bookmarks (Closed)
Patch Set: Split out creation Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 suite('<bookmarks-edit-dialog>', function() { 5 suite('<bookmarks-edit-dialog>', function() {
6 var dialog; 6 var dialog;
7 var lastUpdate; 7 var lastUpdate;
8 var lastCreation;
8 9
9 suiteSetup(function() { 10 suiteSetup(function() {
10 chrome.bookmarks.update = function(id, edit) { 11 chrome.bookmarks.update = function(id, edit) {
11 lastUpdate.id = id; 12 lastUpdate.id = id;
12 lastUpdate.edit = edit; 13 lastUpdate.edit = edit;
13 } 14 };
15 chrome.bookmarks.create = function(node) {
16 lastCreation = node;
17 };
14 }); 18 });
15 19
16 setup(function() { 20 setup(function() {
17 lastUpdate = {}; 21 lastUpdate = {};
calamity 2017/04/03 07:20:48 Reset lastCreation either here or in a teardown.
tsergeant 2017/04/04 01:21:08 Done.
18 dialog = document.createElement('bookmarks-edit-dialog'); 22 dialog = document.createElement('bookmarks-edit-dialog');
19 replaceBody(dialog); 23 replaceBody(dialog);
20 }); 24 });
21 25
22 test('editing an item shows the url field', function() { 26 test('editing an item shows the url field', function() {
23 var item = createItem('0'); 27 var item = createItem('0');
24 dialog.showEditDialog(item); 28 dialog.showEditDialog(item);
25 29
26 assertFalse(dialog.$.url.hidden); 30 assertFalse(dialog.$.url.hidden);
27 }); 31 });
28 32
29 test('editing a folder hides the url field', function() { 33 test('editing a folder hides the url field', function() {
30 var folder = createFolder('0', []); 34 var folder = createFolder('0', []);
31 dialog.showEditDialog(folder); 35 dialog.showEditDialog(folder);
32 36
33 assertTrue(dialog.$.url.hidden); 37 assertTrue(dialog.$.url.hidden);
34 }); 38 });
35 39
40 test('adding a folder hides the url field', function() {
41 dialog.showAddDialog(true, '1');
42 assertTrue(dialog.$.url.hidden);
43 });
44
36 test('editing passes the correct details to the update', function() { 45 test('editing passes the correct details to the update', function() {
37 // Editing an item without changing anything. 46 // Editing an item without changing anything.
38 var item = createItem('1', {url: 'http://website.com', title: 'website'}); 47 var item = createItem('1', {url: 'http://website.com', title: 'website'});
39 dialog.showEditDialog(item); 48 dialog.showEditDialog(item);
40 49
41 MockInteractions.tap(dialog.$.saveButton); 50 MockInteractions.tap(dialog.$.saveButton);
42 51
43 assertEquals(item.id, lastUpdate.id); 52 assertEquals(item.id, lastUpdate.id);
44 assertEquals(item.url, lastUpdate.edit.url); 53 assertEquals(item.url, lastUpdate.edit.url);
45 assertEquals(item.title, lastUpdate.edit.title); 54 assertEquals(item.title, lastUpdate.edit.title);
(...skipping 11 matching lines...) Expand all
57 }); 66 });
58 67
59 test('pressing enter saves and closes dialog', function() { 68 test('pressing enter saves and closes dialog', function() {
60 var item = createItem('1', {url: 'http://www.example.com'}); 69 var item = createItem('1', {url: 'http://www.example.com'});
61 dialog.showEditDialog(item); 70 dialog.showEditDialog(item);
62 71
63 MockInteractions.pressEnter(dialog.$.url); 72 MockInteractions.pressEnter(dialog.$.url);
64 assertFalse(dialog.$.dialog.open); 73 assertFalse(dialog.$.dialog.open);
65 }); 74 });
66 75
76 test('add passes the correct details to the backend', function() {
77 dialog.showAddDialog(false, '1');
78
79 dialog.titleValue_ = 'Permission Site';
80 dialog.urlValue_ = 'permission.site';
81
82 MockInteractions.tap(dialog.$.saveButton);
83
84 assertEquals('1', lastCreation.parentId);
85 assertEquals('http://permission.site', lastCreation.url);
86 assertEquals('Permission Site', lastCreation.title);
87 });
88
67 test('validates urls correctly', function() { 89 test('validates urls correctly', function() {
68 dialog.urlValue_ = 'http://www.example.com'; 90 dialog.urlValue_ = 'http://www.example.com';
69 assertTrue(dialog.validateUrl_()); 91 assertTrue(dialog.validateUrl_());
70 92
71 dialog.urlValue_ = 'https://a@example.com:8080'; 93 dialog.urlValue_ = 'https://a@example.com:8080';
72 assertTrue(dialog.validateUrl_()); 94 assertTrue(dialog.validateUrl_());
73 95
74 dialog.urlValue_ = 'example.com'; 96 dialog.urlValue_ = 'example.com';
75 assertTrue(dialog.validateUrl_()); 97 assertTrue(dialog.validateUrl_());
76 assertEquals('http://example.com', dialog.urlValue_); 98 assertEquals('http://example.com', dialog.urlValue_);
(...skipping 10 matching lines...) Expand all
87 dialog.showEditDialog(item); 109 dialog.showEditDialog(item);
88 110
89 dialog.urlValue_ = ''; 111 dialog.urlValue_ = '';
90 112
91 MockInteractions.tap(dialog.$.saveButton); 113 MockInteractions.tap(dialog.$.saveButton);
92 114
93 assertTrue(dialog.$.url.invalid); 115 assertTrue(dialog.$.url.invalid);
94 assertTrue(dialog.$.dialog.open); 116 assertTrue(dialog.$.dialog.open);
95 }); 117 });
96 }); 118 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698