Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
51fb81e2
Unverified
Commit
51fb81e2
authored
Jun 08, 2017
by
Sean Hammond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract isBrowserExtension() into separate function
parent
eb2ea096
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
31 deletions
+77
-31
index.js
src/annotator/config/index.js
+1
-9
settings.js
src/annotator/config/settings.js
+19
-0
index-test.js
src/annotator/config/test/index-test.js
+22
-22
settings-test.js
src/annotator/config/test/settings-test.js
+35
-0
No files found.
src/annotator/config/index.js
View file @
51fb81e2
...
...
@@ -24,15 +24,7 @@ function configFrom(window_) {
annotations
:
settings
.
annotations
(
window_
.
location
.
href
),
};
var
chromeExt
=
'chrome-extension://'
;
var
mozExt
=
'moz-extension://'
;
var
edgeExt
=
'ms-browser-extension://'
;
// If the client is injected by the browser extension, ignore
// the rest of the host page config.
if
(
config
.
app
.
indexOf
(
chromeExt
)
===
0
||
config
.
app
.
indexOf
(
mozExt
)
===
0
||
config
.
app
.
indexOf
(
edgeExt
)
===
0
)
{
if
(
settings
.
isBrowserExtension
(
config
))
{
return
config
;
}
...
...
src/annotator/config/settings.js
View file @
51fb81e2
...
...
@@ -102,9 +102,28 @@ function configFuncSettingsFrom(window_) {
return
window_
.
hypothesisConfig
();
}
/**
* Return true if the client is from a browser extension.
*
* @returns {boolean} true if this instance of the Hypothesis client is one
* distributed in a browser extension, false if it's one embedded in a
* website.
*
*/
function
isBrowserExtension
(
config
)
{
if
(
config
.
app
.
indexOf
(
'chrome-extension://'
)
===
0
||
config
.
app
.
indexOf
(
'moz-extension://'
)
===
0
||
config
.
app
.
indexOf
(
'ms-browser-extension://'
)
===
0
)
{
return
true
;
}
return
false
;
}
module
.
exports
=
{
app
:
app
,
annotations
:
annotations
,
query
:
query
,
configFuncSettingsFrom
:
configFuncSettingsFrom
,
isBrowserExtension
:
isBrowserExtension
,
};
src/annotator/config/test/index-test.js
View file @
51fb81e2
...
...
@@ -28,6 +28,7 @@ describe('annotator.config', function() {
fakeSettings
.
annotations
=
sinon
.
stub
().
returns
(
null
);
fakeSettings
.
query
=
sinon
.
stub
().
returns
(
null
);
fakeSettings
.
configFuncSettingsFrom
=
sinon
.
stub
().
returns
({});
fakeSettings
.
isBrowserExtension
=
sinon
.
stub
().
returns
(
false
);
});
it
(
'gets the config.app setting'
,
function
()
{
...
...
@@ -188,39 +189,38 @@ describe('annotator.config', function() {
});
context
(
'when the client is injected by the browser extension'
,
function
()
{
beforeEach
(
function
()
{
fakeSettings
.
annotations
.
returns
(
'SOME_ANNOTATION_ID'
);
fakeSharedSettings
.
jsonConfigsFrom
.
returns
({
foo
:
'bar'
});
beforeEach
(
'configure a browser extension client'
,
function
()
{
fakeSettings
.
isBrowserExtension
.
returns
(
true
);
});
it
(
'ignores the host page config on chrome'
,
function
()
{
fakeSettings
.
app
.
returns
(
'chrome-extension://abcdef'
);
var
config
=
configFrom
(
fakeWindow
());
it
(
'still reads the config.app setting from the host page'
,
function
()
{
fakeSettings
.
app
.
returns
(
'SOME_APP_URL'
);
assert
.
equal
(
config
.
app
,
'chrome-extension://abcdef'
);
assert
.
equal
(
config
.
annotations
,
'SOME_ANNOTATION_ID'
);
assert
.
isUndefined
(
config
.
foo
);
assert
.
equal
(
configFrom
(
fakeWindow
()).
app
,
fakeSettings
.
app
());
});
it
(
'
ignores the host page config on firefox
'
,
function
()
{
fakeSettings
.
app
.
returns
(
'moz-extension://abcdef
'
);
it
(
'
still reads the config.query setting from the host page
'
,
function
()
{
fakeSettings
.
query
.
returns
(
'SOME_QUERY
'
);
var
config
=
configFrom
(
fakeWindow
());
assert
.
equal
(
configFrom
(
fakeWindow
()).
query
,
fakeSettings
.
query
());
});
assert
.
equal
(
config
.
app
,
'moz-extension://abcdef'
);
assert
.
equal
(
config
.
annotations
,
'SOME_ANNOTATION_ID'
);
assert
.
isUndefined
(
config
.
foo
);
it
(
'still reads the config.annotations setting from the host page'
,
function
()
{
fakeSettings
.
annotations
.
returns
(
'SOME_ANNOTATION_ID'
);
assert
.
equal
(
configFrom
(
fakeWindow
()).
annotations
,
fakeSettings
.
annotations
());
});
it
(
'ignores
the host page config on ed
ge'
,
function
()
{
fakeS
ettings
.
app
.
returns
(
'ms-browser-extension://abcdef'
);
it
(
'ignores
settings from JSON objects in the host pa
ge'
,
function
()
{
fakeS
haredSettings
.
jsonConfigsFrom
.
returns
({
foo
:
'bar'
}
);
var
config
=
configFrom
(
fakeWindow
());
assert
.
isUndefined
(
configFrom
(
fakeWindow
()).
foo
);
});
assert
.
equal
(
config
.
app
,
'ms-browser-extension://abcdef'
);
assert
.
equal
(
config
.
annotations
,
'SOME_ANNOTATION_ID'
);
assert
.
isUndefined
(
config
.
foo
);
it
(
'ignores settings from the hypothesisConfig() function in the host page'
,
function
()
{
fakeSettings
.
configFuncSettingsFrom
.
returns
({
foo
:
'bar'
});
assert
.
isUndefined
(
configFrom
(
fakeWindow
()).
foo
);
});
});
...
...
src/annotator/config/test/settings-test.js
View file @
51fb81e2
...
...
@@ -236,4 +236,39 @@ describe('annotation.config.settings', function() {
});
});
});
describe
(
'#isBrowserExtension'
,
function
()
{
[
{
url
:
'chrome-extension://abcxyz'
,
returns
:
true
,
},
{
url
:
'moz-extension://abcxyz'
,
returns
:
true
,
},
{
url
:
'ms-browser-extension://abcxyz'
,
returns
:
true
,
},
{
url
:
'http://partner.org'
,
returns
:
false
,
},
{
url
:
'https://partner.org'
,
returns
:
false
,
},
{
url
:
'ftp://partner.org'
,
returns
:
false
,
},
].
forEach
(
function
(
test
)
{
it
(
'returns '
+
test
.
returns
+
' for '
+
test
.
url
,
function
()
{
assert
.
equal
(
settings
.
isBrowserExtension
({
app
:
test
.
url
}),
test
.
returns
);
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment