-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename protocolfilter setting, fix issue and add test.
b/205134049
- Loading branch information
1 parent
64694cb
commit 4f70dcc
Showing
6 changed files
with
173 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<!-- | ||
This is a basic test of the h5vcc.settings. | ||
--> | ||
|
||
<html> | ||
<head> | ||
<title>Cobalt h5vcc.settings</title> | ||
<script src='black_box_js_test_utils.js'></script> | ||
</head> | ||
<body> | ||
<script> | ||
const reset = () => window.h5vcc.settings.set('httpProtocolFilter', ''); | ||
const set = config => window.h5vcc.settings.set('httpProtocolFilter', JSON.stringify(config)); | ||
const get = () => window.h5vcc.settings.getPersistentSettingAsString('httpProtocolFilter'); | ||
|
||
const assertSetGetFixed = (config, fixedConfig) => { | ||
assertTrue(set(config)); | ||
assertFalse(set(config)); | ||
const storedConfig = JSON.parse(get()); | ||
assertTrue(Array.isArray(fixedConfig) && Array.isArray(storedConfig)); | ||
fixedConfig.forEach((line, i) => { | ||
const storedLine = storedConfig[i]; | ||
Object.keys(line).forEach(key => { | ||
assertTrue(typeof(line[key]) === 'string'); | ||
assertEqual(line[key], storedLine[key]); | ||
}); | ||
}); | ||
} | ||
const assertSetGet = config => { | ||
assertSetGetFixed(config, config); | ||
}; | ||
const assertSetFailed = config => { | ||
assertFalse(set(config)); | ||
}; | ||
|
||
setupFinished(); | ||
|
||
assertFalse(window.h5vcc.settings.set('protocolfilter', '')); | ||
assertFalse(window.h5vcc.settings.set('protocolfilter', '""')); | ||
assertFalse(window.h5vcc.settings.set('protocolfilter', '[]')); | ||
assertFalse(window.h5vcc.settings.set('protocolfilter', '{}')); | ||
|
||
reset(); | ||
assertEqual('', get()); | ||
[ | ||
{}, [], '', null, 1, true, [{}] | ||
].forEach(assertSetFailed); | ||
|
||
[ | ||
[ | ||
{origin: 'example.com:443', altSvc: 'h3'}, | ||
{origin: '*', altSvc: 'h3'}, | ||
], | ||
[ | ||
{origin: 'a.example.com:443', altSvc: 'h3'}, | ||
{origin: 'b.example.com:443', altSvc: 'h2'}, | ||
{origin: 'c.example.com:443', altSvc: 'h3'}, | ||
{origin: 'd.example.com:443', altSvc: 'h2'}, | ||
{origin: '*example.com:443', altSvc: 'h3'}, | ||
{origin: '*', altSvc: 'h3'}, | ||
], | ||
].forEach(assertSetGet); | ||
assertSetGetFixed([ | ||
{origin: 'example.com:443', altSvc: 'h3'}, | ||
{origin: '*', mainSvc: 'h3'}, | ||
], | ||
[ | ||
{origin: 'example.com:443', altSvc: 'h3'}, | ||
]); | ||
assertTrue(reset()); | ||
assertFalse(reset()); | ||
onEndTest(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2022 The Cobalt Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Tests h5vcc.settings functionality.""" | ||
|
||
from cobalt.black_box_tests import black_box_tests | ||
from cobalt.black_box_tests.threaded_web_server import ThreadedWebServer | ||
|
||
|
||
class H5vccSettingsTest(black_box_tests.BlackBoxTestCase): | ||
|
||
def test_service_worker_fetch(self): | ||
with ThreadedWebServer(binding_address=self.GetBindingAddress()) as server: | ||
url = server.GetURL(file_name='testdata/h5vcc_settings.html') | ||
with self.CreateCobaltRunner(url=url) as runner: | ||
runner.WaitForJSTestsSetup() | ||
self.assertTrue(runner.JSTestsSucceeded()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters