OLD | NEW |
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 Loading... |
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 |
| 59 test('validates urls correctly', function() { |
| 60 dialog.urlValue_ = 'http://www.example.com'; |
| 61 assertTrue(dialog.validateUrl_()); |
| 62 |
| 63 dialog.urlValue_ = 'https://a@example.com:8080'; |
| 64 assertTrue(dialog.validateUrl_()); |
| 65 |
| 66 dialog.urlValue_ = 'example.com'; |
| 67 assertTrue(dialog.validateUrl_()); |
| 68 assertEquals('http://example.com', dialog.urlValue_); |
| 69 |
| 70 dialog.urlValue_ = ''; |
| 71 assertFalse(dialog.validateUrl_()); |
| 72 |
| 73 dialog.urlValue_ = '~~~example.com~~~'; |
| 74 assertFalse(dialog.validateUrl_()); |
| 75 }); |
| 76 |
| 77 test('doesn\'t save when URL is invalid', function() { |
| 78 var item = createItem('0'); |
| 79 dialog.showEditDialog(item); |
| 80 |
| 81 dialog.urlValue_ = ''; |
| 82 |
| 83 MockInteractions.tap(dialog.$.saveButton); |
| 84 |
| 85 assertTrue(dialog.$.url.invalid); |
| 86 assertTrue(dialog.$.dialog.open); |
| 87 }); |
| 88 |
58 }); | 89 }); |
OLD | NEW |