Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/atoms/html5/html5_browser.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* @fileoverview Helper function to determine which HTML5 features are
20
* supported by browsers..
21
*/
22
23
goog.provide('bot.html5');
24
25
goog.require('bot');
26
goog.require('bot.Error');
27
goog.require('bot.ErrorCode');
28
goog.require('bot.userAgent');
29
goog.require('goog.userAgent');
30
goog.require('goog.userAgent.product');
31
32
33
/**
34
* Identifier for supported HTML5 API in Webdriver.
35
*
36
* @enum {string}
37
*/
38
bot.html5.API = {
39
APPCACHE: 'appcache',
40
BROWSER_CONNECTION: 'browser_connection',
41
DATABASE: 'database',
42
GEOLOCATION: 'location',
43
LOCAL_STORAGE: 'local_storage',
44
SESSION_STORAGE: 'session_storage',
45
VIDEO: 'video',
46
AUDIO: 'audio',
47
CANVAS: 'canvas'
48
};
49
50
51
/**
52
* True if the current browser is IE version 8 or earlier.
53
* @private {boolean}
54
* @const
55
*/
56
bot.html5.IS_IE8_OR_EARLIER_ = goog.userAgent.IE &&
57
!bot.userAgent.isEngineVersion(9);
58
59
60
/**
61
* True if the current browser is Safari version 4 or earlier.
62
* @private {boolean}
63
* @const
64
*/
65
bot.html5.IS_SAFARI4_OR_EARLIER_ = goog.userAgent.product.SAFARI &&
66
!bot.userAgent.isProductVersion(5);
67
68
69
/**
70
* True if the browser is Android version 2.2 (Froyo) or earlier.
71
* @private {boolean}
72
* @const
73
*/
74
bot.html5.IS_ANDROID_FROYO_OR_EARLIER_ = goog.userAgent.product.ANDROID &&
75
!bot.userAgent.isProductVersion(2.3);
76
77
78
/**
79
* True if the current browser is Safari 5 on Windows.
80
* @private {boolean}
81
* @const
82
*/
83
bot.html5.IS_SAFARI_WINDOWS_ = goog.userAgent.WINDOWS &&
84
goog.userAgent.product.SAFARI &&
85
(bot.userAgent.isProductVersion(4)) &&
86
!bot.userAgent.isProductVersion(6);
87
88
89
/**
90
* Checks if the browser supports an HTML5 feature.
91
*
92
* @param {bot.html5.API} api HTML5 API identifier.
93
* @param {!Window=} opt_window The window to be accessed;
94
* defaults to the main window.
95
* @return {boolean} Whether the browser supports the feature.
96
*/
97
bot.html5.isSupported = function(api, opt_window) {
98
var win = opt_window || bot.getWindow();
99
100
switch (api) {
101
case bot.html5.API.APPCACHE:
102
// IE8 does not support application cache, though the APIs exist.
103
if (bot.html5.IS_IE8_OR_EARLIER_) {
104
return false;
105
}
106
return goog.isDefAndNotNull(win.applicationCache);
107
108
case bot.html5.API.BROWSER_CONNECTION:
109
return goog.isDefAndNotNull(win.navigator) &&
110
goog.isDefAndNotNull(win.navigator.onLine);
111
112
case bot.html5.API.DATABASE:
113
// Safari4 database API does not allow writes.
114
if (bot.html5.IS_SAFARI4_OR_EARLIER_) {
115
return false;
116
}
117
// Android Froyo does not support database, though the APIs exist.
118
if (bot.html5.IS_ANDROID_FROYO_OR_EARLIER_) {
119
return false;
120
}
121
return goog.isDefAndNotNull(win.openDatabase);
122
123
case bot.html5.API.GEOLOCATION:
124
// Safari 4,5 on Windows do not support geolocation, see:
125
// https://discussions.apple.com/thread/3547900
126
if (bot.html5.IS_SAFARI_WINDOWS_) {
127
return false;
128
}
129
return goog.isDefAndNotNull(win.navigator) &&
130
goog.isDefAndNotNull(win.navigator.geolocation);
131
132
case bot.html5.API.LOCAL_STORAGE:
133
// IE8 does not support local storage, though the APIs exist.
134
if (bot.html5.IS_IE8_OR_EARLIER_) {
135
return false;
136
}
137
return goog.isDefAndNotNull(win.localStorage);
138
139
case bot.html5.API.SESSION_STORAGE:
140
// IE8 does not support session storage, though the APIs exist.
141
if (bot.html5.IS_IE8_OR_EARLIER_) {
142
return false;
143
}
144
return goog.isDefAndNotNull(win.sessionStorage) &&
145
// To avoid browsers that only support this API partially
146
// like some versions of FF.
147
goog.isDefAndNotNull(win.sessionStorage.clear);
148
149
default:
150
throw new bot.Error(bot.ErrorCode.UNKNOWN_ERROR,
151
'Unsupported API identifier provided as parameter');
152
}
153
};
154
155