summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsivedesign/test/browser_responsiveui_customuseragent.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/responsivedesign/test/browser_responsiveui_customuseragent.js')
-rw-r--r--devtools/client/responsivedesign/test/browser_responsiveui_customuseragent.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/devtools/client/responsivedesign/test/browser_responsiveui_customuseragent.js b/devtools/client/responsivedesign/test/browser_responsiveui_customuseragent.js
new file mode 100644
index 000000000..35efc4c14
--- /dev/null
+++ b/devtools/client/responsivedesign/test/browser_responsiveui_customuseragent.js
@@ -0,0 +1,56 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const TEST_URI = "data:text/html, Custom User Agent test";
+const DEFAULT_UA = Cc["@mozilla.org/network/protocol;1?name=http"]
+ .getService(Ci.nsIHttpProtocolHandler)
+ .userAgent;
+const CHROME_UA = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36" +
+ " (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
+add_task(function* () {
+ yield addTab(TEST_URI);
+
+ let {rdm, manager} = yield openRDM();
+ yield testUserAgent(DEFAULT_UA);
+
+ info("Setting UA to " + CHROME_UA);
+ yield setUserAgent(CHROME_UA, rdm, manager);
+ yield testUserAgent(CHROME_UA);
+
+ info("Resetting UA");
+ yield setUserAgent("", rdm, manager);
+ yield testUserAgent(DEFAULT_UA);
+
+ info("Setting UA to " + CHROME_UA);
+ yield setUserAgent(CHROME_UA, rdm, manager);
+ yield testUserAgent(CHROME_UA);
+
+ info("Closing responsive mode");
+
+ yield closeRDM(rdm);
+ yield testUserAgent(DEFAULT_UA);
+});
+
+function* setUserAgent(ua, rdm, manager) {
+ let input = rdm.userAgentInput;
+ input.focus();
+ input.value = ua;
+ let onUAChanged = once(manager, "userAgentChanged");
+ input.blur();
+ yield onUAChanged;
+
+ if (ua !== "") {
+ ok(input.hasAttribute("attention"), "UA input should be highlighted");
+ } else {
+ ok(!input.hasAttribute("attention"), "UA input shouldn't be highlighted");
+ }
+}
+
+function* testUserAgent(value) {
+ let ua = yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
+ return content.navigator.userAgent;
+ });
+ is(ua, value, `UA should be set to ${value}`);
+}