diff options
author | michaelpg <michaelpg@chromium.org> | 2015-11-03 19:07:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-04 03:09:09 +0000 |
commit | 814937a67b590f7b362d15c2851de813b8ef5543 (patch) | |
tree | e5d51e0737395c268671a73f2e3975960279b8c8 /ui | |
parent | 1017e61c4a4a1edeac49f3173b107b6116ad26c5 (diff) | |
download | chromium_src-814937a67b590f7b362d15c2851de813b8ef5543.zip chromium_src-814937a67b590f7b362d15c2851de813b8ef5543.tar.gz chromium_src-814937a67b590f7b362d15c2851de813b8ef5543.tar.bz2 |
Importing a "non-existent" URL like "chrome://md-settings/404"
redirects to chrome://md-settings. We rely on this behavior
for navigation, e.g. chrome://md-settings/advanced.
In a browser test, importing a URL like this loads the
the entire page, which isn't what we want and leads to
duplicate scripts running (it seems the browsePreload URL
isn't deduped with HTML imports). This results in
document.registerElement failing in a Polymer script
in chrome://resources, preventing mocha from handling the
raw error (see #4 below).
The hack is to replace document.registerElement with a
function that can throw an error from within mocha.
===============================================================================
More detailed explanation, using cr_settings_browsertest.js as an example:
1. CrSettingsBrowserTest sets browsePreload to
chrome://md-settings/prefs/prefs.html, which imports Polymer when it loads.
2. BUG: CrSettingsBrowserTest.CrSettingsTest imports
chrome://md-settings/foo.html. This URL isn't redirected so it just loads
chrome://md-settings.
3A. chrome://md-settings loads polymer_config.js (which overwrites Polymer) and
then loads a Polymer element. This element calls Polymer({}), resulting in
a type error.
3B. Or, chrome://md-settings loads chrome://md-settings/prefs/prefs.html, which
attempts to register a Polymer element that was already registered.
The call to document.registerElement() in chrome://resources/polymer/v1_0/polymer/polymer-micro-extracted.js
fails.
4. Chrome treats chrome://resources like a different origin, so the only error
information that the test gets is "Script error":
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror#Notes
Detecting the bug in (2) is hard because errors generated outside of
chrome://md-settings are opaque.
3A can be handled with a console.error message in polymer_config.js.
3B can be handled by wrapping document.registerElement so the actual error is
thrown in browser test's context.
===============================================================================
Before:
[27340:27340:0929/163040:INFO:CONSOLE(1324)] "Running TestCase CrSettingsBrowserTest.CrSettingsTest", source: test_api.js (1324)
[27340:27340:0929/163040:ERROR:CONSOLE(39)] "Mocha test failed: SettingsCheckbox "before all" hook
Error: Script error. (:0)
", source: mocha_adapter.js (39)
[27340:27340:0929/163040:ERROR:web_ui_test_handler.cc(76)] Test Errors: 1/1 tests had failed assertions.
After:
[21356:21356:0930/114606:INFO:CONSOLE(1324)] "Running TestCase CrSettingsBrowserTest.CrSettingsTest", source: test_api.js (1324)
[21356:21356:0930/114606:ERROR:CONSOLE(8)] "Polymer being defined again", source: chrome://resources/js/polymer_config.js (8)
[21356:21356:0930/114606:ERROR:CONSOLE(68)] "If the call to document.registerElement failed because a type is already registered, perhaps you have loaded a script twice. Incorrect resource URLs can redirect to base WebUI pages; make sure the following URLs are correct and unique:
chrome://md-settings/settings-checkbox/settings-checkbox.html
chrome://resources/polymer/v1_0/iron-test-helpers/iron-test-helpers.html
chrome://resources/polymer/v1_0/polymer/polymer.html
", source: polymer_browser_test_base.js (68)
[21356:21356:0930/114606:ERROR:CONSOLE(39)] "Mocha test failed: SettingsCheckbox "before all" hook
Error: Uncaught NotSupportedError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'cr-settings-prefs'. A type with that name is already registered. (polymer_browser_test_base.js:71)
", source: mocha_adapter.js (39)
[21356:21356:0930/114606:ERROR:web_ui_test_handler.cc(76)] Test Errors: 1/1 tests had failed assertions.
Review URL: https://codereview.chromium.org/1377943007
Cr-Commit-Position: refs/heads/master@{#357743}
Diffstat (limited to 'ui')
-rw-r--r-- | ui/webui/resources/js/polymer_config.js | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/ui/webui/resources/js/polymer_config.js b/ui/webui/resources/js/polymer_config.js index 3b20eae..6b432d9 100644 --- a/ui/webui/resources/js/polymer_config.js +++ b/ui/webui/resources/js/polymer_config.js @@ -2,4 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -Polymer = {dom: 'shadow'}; +if (typeof Polymer == 'undefined') + Polymer = {dom: 'shadow'}; +else + console.error('Polymer is already defined.'); |