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

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

Issue 2769863002: MD Bookmarks: Validate URL input when editing a bookmark (Closed)
Patch Set: Rebase Created 3 years, 9 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
« no previous file with comments | « chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 suiteSetup(function() { 9 suiteSetup(function() {
10 chrome.bookmarks.update = function(id, edit) { 10 chrome.bookmarks.update = function(id, edit) {
(...skipping 17 matching lines...) Expand all
28 28
29 test('editing a folder hides the url field', function() { 29 test('editing a folder hides the url field', function() {
30 var folder = createFolder('0', []); 30 var folder = createFolder('0', []);
31 dialog.showEditDialog(folder); 31 dialog.showEditDialog(folder);
32 32
33 assertTrue(dialog.$.url.hidden); 33 assertTrue(dialog.$.url.hidden);
34 }); 34 });
35 35
36 test('editing passes the correct details to the update', function() { 36 test('editing passes the correct details to the update', function() {
37 // Editing an item without changing anything. 37 // Editing an item without changing anything.
38 var item = createItem('1', {url: 'www.website.com', title: 'website'}); 38 var item = createItem('1', {url: 'http://website.com', title: 'website'});
39 dialog.showEditDialog(item); 39 dialog.showEditDialog(item);
40 40
41 MockInteractions.tap(dialog.$.saveButton); 41 MockInteractions.tap(dialog.$.saveButton);
42 42
43 assertEquals(item.id, lastUpdate.id); 43 assertEquals(item.id, lastUpdate.id);
44 assertEquals(item.url, lastUpdate.edit.url); 44 assertEquals(item.url, lastUpdate.edit.url);
45 assertEquals(item.title, lastUpdate.edit.title); 45 assertEquals(item.title, lastUpdate.edit.title);
46 46
47 // Editing a folder, changing the title. 47 // Editing a folder, changing the title.
48 var folder = createFolder('2', [], {title: 'Cool Sites'}); 48 var folder = createFolder('2', [], {title: 'Cool Sites'});
49 dialog.showEditDialog(folder); 49 dialog.showEditDialog(folder);
50 dialog.titleValue_ = 'Awesome websites'; 50 dialog.titleValue_ = 'Awesome websites';
51 51
52 MockInteractions.tap(dialog.$.saveButton); 52 MockInteractions.tap(dialog.$.saveButton);
53 53
54 assertEquals(folder.id, lastUpdate.id); 54 assertEquals(folder.id, lastUpdate.id);
55 assertEquals(undefined, lastUpdate.edit.url); 55 assertEquals(undefined, lastUpdate.edit.url);
56 assertEquals('Awesome websites', lastUpdate.edit.title); 56 assertEquals('Awesome websites', lastUpdate.edit.title);
57 }); 57 });
58 58
59 test('pressing enter saves and closes dialog', function() { 59 test('pressing enter saves and closes dialog', function() {
60 var item = createItem('1', {url: 'http://www.example.com'}); 60 var item = createItem('1', {url: 'http://www.example.com'});
61 dialog.showEditDialog(item); 61 dialog.showEditDialog(item);
62 62
63 MockInteractions.pressEnter(dialog.$.url); 63 MockInteractions.pressEnter(dialog.$.url);
64 assertFalse(dialog.$.dialog.open); 64 assertFalse(dialog.$.dialog.open);
65 }); 65 });
66
67 test('validates urls correctly', function() {
68 dialog.urlValue_ = 'http://www.example.com';
69 assertTrue(dialog.validateUrl_());
70
71 dialog.urlValue_ = 'https://a@example.com:8080';
72 assertTrue(dialog.validateUrl_());
73
74 dialog.urlValue_ = 'example.com';
75 assertTrue(dialog.validateUrl_());
76 assertEquals('http://example.com', dialog.urlValue_);
77
78 dialog.urlValue_ = '';
79 assertFalse(dialog.validateUrl_());
80
81 dialog.urlValue_ = '~~~example.com~~~';
82 assertFalse(dialog.validateUrl_());
83 });
84
85 test('doesn\'t save when URL is invalid', function() {
86 var item = createItem('0');
87 dialog.showEditDialog(item);
88
89 dialog.urlValue_ = '';
90
91 MockInteractions.tap(dialog.$.saveButton);
92
93 assertTrue(dialog.$.url.invalid);
94 assertTrue(dialog.$.dialog.open);
95 });
66 }); 96 });
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698