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

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: Rebase 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 = {};
22 lastCreation = {};
18 dialog = document.createElement('bookmarks-edit-dialog'); 23 dialog = document.createElement('bookmarks-edit-dialog');
19 replaceBody(dialog); 24 replaceBody(dialog);
20 }); 25 });
21 26
22 test('editing an item shows the url field', function() { 27 test('editing an item shows the url field', function() {
23 var item = createItem('0'); 28 var item = createItem('0');
24 dialog.showEditDialog(item); 29 dialog.showEditDialog(item);
25 30
26 assertFalse(dialog.$.url.hidden); 31 assertFalse(dialog.$.url.hidden);
27 }); 32 });
28 33
29 test('editing a folder hides the url field', function() { 34 test('editing a folder hides the url field', function() {
30 var folder = createFolder('0', []); 35 var folder = createFolder('0', []);
31 dialog.showEditDialog(folder); 36 dialog.showEditDialog(folder);
32 37
33 assertTrue(dialog.$.url.hidden); 38 assertTrue(dialog.$.url.hidden);
34 }); 39 });
35 40
41 test('adding a folder hides the url field', function() {
42 dialog.showAddDialog(true, '1');
43 assertTrue(dialog.$.url.hidden);
44 });
45
36 test('editing passes the correct details to the update', function() { 46 test('editing passes the correct details to the update', function() {
37 // Editing an item without changing anything. 47 // Editing an item without changing anything.
38 var item = createItem('1', {url: 'http://website.com', title: 'website'}); 48 var item = createItem('1', {url: 'http://website.com', title: 'website'});
39 dialog.showEditDialog(item); 49 dialog.showEditDialog(item);
40 50
41 MockInteractions.tap(dialog.$.saveButton); 51 MockInteractions.tap(dialog.$.saveButton);
42 52
43 assertEquals(item.id, lastUpdate.id); 53 assertEquals(item.id, lastUpdate.id);
44 assertEquals(item.url, lastUpdate.edit.url); 54 assertEquals(item.url, lastUpdate.edit.url);
45 assertEquals(item.title, lastUpdate.edit.title); 55 assertEquals(item.title, lastUpdate.edit.title);
(...skipping 11 matching lines...) Expand all
57 }); 67 });
58 68
59 test('pressing enter saves and closes dialog', function() { 69 test('pressing enter saves and closes dialog', function() {
60 var item = createItem('1', {url: 'http://www.example.com'}); 70 var item = createItem('1', {url: 'http://www.example.com'});
61 dialog.showEditDialog(item); 71 dialog.showEditDialog(item);
62 72
63 MockInteractions.pressEnter(dialog.$.url); 73 MockInteractions.pressEnter(dialog.$.url);
64 assertFalse(dialog.$.dialog.open); 74 assertFalse(dialog.$.dialog.open);
65 }); 75 });
66 76
77 test('add passes the correct details to the backend', function() {
78 dialog.showAddDialog(false, '1');
79
80 dialog.titleValue_ = 'Permission Site';
81 dialog.urlValue_ = 'permission.site';
82
83 MockInteractions.tap(dialog.$.saveButton);
84
85 assertEquals('1', lastCreation.parentId);
86 assertEquals('http://permission.site', lastCreation.url);
87 assertEquals('Permission Site', lastCreation.title);
88 });
89
67 test('validates urls correctly', function() { 90 test('validates urls correctly', function() {
68 dialog.urlValue_ = 'http://www.example.com'; 91 dialog.urlValue_ = 'http://www.example.com';
69 assertTrue(dialog.validateUrl_()); 92 assertTrue(dialog.validateUrl_());
70 93
71 dialog.urlValue_ = 'https://a@example.com:8080'; 94 dialog.urlValue_ = 'https://a@example.com:8080';
72 assertTrue(dialog.validateUrl_()); 95 assertTrue(dialog.validateUrl_());
73 96
74 dialog.urlValue_ = 'example.com'; 97 dialog.urlValue_ = 'example.com';
75 assertTrue(dialog.validateUrl_()); 98 assertTrue(dialog.validateUrl_());
76 assertEquals('http://example.com', dialog.urlValue_); 99 assertEquals('http://example.com', dialog.urlValue_);
(...skipping 10 matching lines...) Expand all
87 dialog.showEditDialog(item); 110 dialog.showEditDialog(item);
88 111
89 dialog.urlValue_ = ''; 112 dialog.urlValue_ = '';
90 113
91 MockInteractions.tap(dialog.$.saveButton); 114 MockInteractions.tap(dialog.$.saveButton);
92 115
93 assertTrue(dialog.$.url.invalid); 116 assertTrue(dialog.$.url.invalid);
94 assertTrue(dialog.$.dialog.open); 117 assertTrue(dialog.$.dialog.open);
95 }); 118 });
96 }); 119 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698