Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 | 5 |
| 6 /** | 6 /** |
| 7 * @fileoverview The local InstantExtended NTP. | 7 * @fileoverview The local InstantExtended NTP. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Controls rendering the new tab page for InstantExtended. | 11 * Controls rendering the new tab page for InstantExtended. |
| 12 * @param {Object} location window.location or a mock. | 12 * @param {Object} testData Mock data to test the local NTP. |
| 13 * @return {Object} A limited interface for testing the local NTP. | 13 * @return {Object} A limited interface for testing the local NTP. |
| 14 */ | 14 */ |
| 15 function LocalNTP(location) { | 15 function LocalNTP(testData) { |
| 16 <include src="../../../../ui/webui/resources/js/assert.js"> | 16 <include src="../../../../ui/webui/resources/js/assert.js"> |
| 17 | 17 |
| 18 | 18 |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Enum for classnames. | 21 * Enum for classnames. |
| 22 * @enum {string} | 22 * @enum {string} |
| 23 * @const | 23 * @const |
| 24 */ | 24 */ |
| 25 var CLASSES = { | 25 var CLASSES = { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 246 |
| 247 /** @type {number} @const */ | 247 /** @type {number} @const */ |
| 248 var MAX_NUM_COLUMNS = 4; | 248 var MAX_NUM_COLUMNS = 4; |
| 249 | 249 |
| 250 | 250 |
| 251 /** @type {number} @const */ | 251 /** @type {number} @const */ |
| 252 var NUM_ROWS = 2; | 252 var NUM_ROWS = 2; |
| 253 | 253 |
| 254 | 254 |
| 255 /** | 255 /** |
| 256 * Mock data to test the local NTP. | |
| 257 * @type {Object} | |
| 258 * const | |
| 259 * */ | |
| 260 var mockTestData = testData; | |
| 261 | |
| 262 /** | |
| 256 * Minimum total padding to give to the left and right of the most visited | 263 * Minimum total padding to give to the left and right of the most visited |
| 257 * section. Used to determine how many tiles to show. | 264 * section. Used to determine how many tiles to show. |
| 258 * @type {number} | 265 * @type {number} |
| 259 * @const | 266 * @const |
| 260 */ | 267 */ |
| 261 var MIN_TOTAL_HORIZONTAL_PADDING = 200; | 268 var MIN_TOTAL_HORIZONTAL_PADDING = 200; |
| 262 | 269 |
| 263 | 270 |
| 264 /** | 271 /** |
| 265 * The filename for a most visited iframe src which shows a page title. | 272 * The filename for a most visited iframe src which shows a page title. |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 return window.chrome.embeddedSearch; | 878 return window.chrome.embeddedSearch; |
| 872 return null; | 879 return null; |
| 873 } | 880 } |
| 874 | 881 |
| 875 | 882 |
| 876 /** | 883 /** |
| 877 * @return {boolean} True if this is a Google page and not some other search | 884 * @return {boolean} True if this is a Google page and not some other search |
| 878 * provider. Used to determine whether to show the logo and fakebox. | 885 * provider. Used to determine whether to show the logo and fakebox. |
| 879 */ | 886 */ |
| 880 function isGooglePage() { | 887 function isGooglePage() { |
| 881 return location.href.indexOf('isGoogle') != -1; | 888 if (window.localNTPUnitTest && mockTestData) |
|
samarth
2013/07/12 17:16:06
Having a separate code path for the test kind of d
kmadhusu
2013/07/15 22:21:51
Fixed. Instead of modifying the codepath, I update
| |
| 889 return mockTestData.isGooglePage; | |
| 890 | |
| 891 return templateData.isGooglePage; | |
| 882 } | 892 } |
| 883 | 893 |
| 884 | 894 |
| 885 /** | 895 /** |
| 886 * Extract the desired navigation behavior from a click button. | 896 * Extract the desired navigation behavior from a click button. |
| 887 * @param {number} button The Event#button property of a click event. | 897 * @param {number} button The Event#button property of a click event. |
| 888 * @return {WindowOpenDisposition} The desired behavior for | 898 * @return {WindowOpenDisposition} The desired behavior for |
| 889 * navigateContentWindow. | 899 * navigateContentWindow. |
| 890 */ | 900 */ |
| 891 function getDispositionFromClickButton(button) { | 901 function getDispositionFromClickButton(button) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 905 notification = $(IDS.NOTIFICATION); | 915 notification = $(IDS.NOTIFICATION); |
| 906 attribution = $(IDS.ATTRIBUTION); | 916 attribution = $(IDS.ATTRIBUTION); |
| 907 ntpContents = $(IDS.NTP_CONTENTS); | 917 ntpContents = $(IDS.NTP_CONTENTS); |
| 908 | 918 |
| 909 for (var i = 0; i < NUM_ROWS; i++) { | 919 for (var i = 0; i < NUM_ROWS; i++) { |
| 910 var row = document.createElement('div'); | 920 var row = document.createElement('div'); |
| 911 row.classList.add(CLASSES.ROW); | 921 row.classList.add(CLASSES.ROW); |
| 912 tilesContainer.appendChild(row); | 922 tilesContainer.appendChild(row); |
| 913 } | 923 } |
| 914 | 924 |
| 915 if (isGooglePage()) { | 925 if (isGooglePage()) { |
|
samarth
2013/07/12 17:16:06
This is now simple enough that I would just inline
kmadhusu
2013/07/15 22:21:51
Done.
| |
| 916 var logo = document.createElement('div'); | 926 var logo = document.createElement('div'); |
| 917 logo.id = IDS.LOGO; | 927 logo.id = IDS.LOGO; |
| 918 | 928 |
| 919 fakebox = document.createElement('div'); | 929 fakebox = document.createElement('div'); |
| 920 fakebox.id = IDS.FAKEBOX; | 930 fakebox.id = IDS.FAKEBOX; |
| 921 fakebox.innerHTML = | 931 fakebox.innerHTML = |
| 922 '<input autocomplete="off" tabindex="-1" aria-hidden="true">' + | 932 '<input autocomplete="off" tabindex="-1" aria-hidden="true">' + |
| 923 '<div id=cursor></div>'; | 933 '<div id=cursor></div>'; |
| 924 | 934 |
| 925 ntpContents.insertBefore(fakebox, ntpContents.firstChild); | 935 ntpContents.insertBefore(fakebox, ntpContents.firstChild); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 document.addEventListener('DOMContentLoaded', init); | 1017 document.addEventListener('DOMContentLoaded', init); |
| 1008 } | 1018 } |
| 1009 | 1019 |
| 1010 return { | 1020 return { |
| 1011 init: init, | 1021 init: init, |
| 1012 listen: listen | 1022 listen: listen |
| 1013 }; | 1023 }; |
| 1014 } | 1024 } |
| 1015 | 1025 |
| 1016 if (!window.localNTPUnitTest) { | 1026 if (!window.localNTPUnitTest) { |
| 1017 LocalNTP(location).listen(); | 1027 LocalNTP(undefined).listen(); |
| 1018 } | 1028 } |
| OLD | NEW |