Debian Codegraph @

closure-library/closure/goog/testing/mockuseragent_test.js

raw
1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.testing.MockUserAgentTest');
16
17 goog.require('goog.dispose');
18 goog.require('goog.testing.MockUserAgent');
19 goog.require('goog.testing.jsunit');
20 goog.require('goog.userAgent');
21
22 goog.setTestOnly('goog.testing.MockUserAgentTest');
23
24 var mockUserAgent;
25
26 function setUp() {
27 mockUserAgent = new goog.testing.MockUserAgent();
28 }
29
30 function tearDown() {
31 goog.dispose(mockUserAgent);
32 assertFalse(mockUserAgent.installed_);
33 }
34
35 function testMockUserAgentInstall() {
36 var originalUserAgentFunction = goog.userAgent.getUserAgentString;
37
38 assertFalse(!!mockUserAgent.installed_);
39
40 mockUserAgent.install();
41 assertTrue(mockUserAgent.installed_);
42 assertNotEquals(goog.userAgent.getUserAgentString, originalUserAgentFunction);
43
44 mockUserAgent.uninstall();
45 assertFalse(mockUserAgent.installed_);
46 assertEquals(originalUserAgentFunction, goog.userAgent.getUserAgentString);
47 }
48
49 function testMockUserAgentGetAgent() {
50 var uaString = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) ' +
51 'AppleWebKit/525.13 (KHTML, like Gecko) ' +
52 'Chrome/0.2.149.27 Safari/525.13';
53
54 mockUserAgent = new goog.testing.MockUserAgent();
55 mockUserAgent.setUserAgentString(uaString);
56 mockUserAgent.install();
57
58 assertTrue(mockUserAgent.installed_);
59 assertEquals(uaString, goog.userAgent.getUserAgentString());
60 }
61
62 function testMockUserAgentNavigator() {
63 var fakeNavigator = {};
64
65 mockUserAgent = new goog.testing.MockUserAgent();
66 mockUserAgent.setNavigator(fakeNavigator);
67 mockUserAgent.install();
68
69 assertTrue(mockUserAgent.installed_);
70 assertEquals(fakeNavigator, goog.userAgent.getNavigator());
71 }
72
73 function testMockUserAgentDocumentMode() {
74 var fakeDocumentMode = -1;
75
76 mockUserAgent = new goog.testing.MockUserAgent();
77 mockUserAgent.setDocumentMode(fakeDocumentMode);
78 mockUserAgent.install();
79
80 assertTrue(mockUserAgent.installed_);
81 assertEquals(fakeDocumentMode, goog.userAgent.getDocumentMode_());
82 assertEquals(fakeDocumentMode, goog.userAgent.DOCUMENT_MODE);
83 }