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_) {
...
@@ -24,15 +24,7 @@ function configFrom(window_) {
annotations
:
settings
.
annotations
(
window_
.
location
.
href
),
annotations
:
settings
.
annotations
(
window_
.
location
.
href
),
};
};
var
chromeExt
=
'chrome-extension://'
;
if
(
settings
.
isBrowserExtension
(
config
))
{
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
)
{
return
config
;
return
config
;
}
}
...
...
src/annotator/config/settings.js
View file @
51fb81e2
...
@@ -102,9 +102,28 @@ function configFuncSettingsFrom(window_) {
...
@@ -102,9 +102,28 @@ function configFuncSettingsFrom(window_) {
return
window_
.
hypothesisConfig
();
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
=
{
module
.
exports
=
{
app
:
app
,
app
:
app
,
annotations
:
annotations
,
annotations
:
annotations
,
query
:
query
,
query
:
query
,
configFuncSettingsFrom
:
configFuncSettingsFrom
,
configFuncSettingsFrom
:
configFuncSettingsFrom
,
isBrowserExtension
:
isBrowserExtension
,
};
};
src/annotator/config/test/index-test.js
View file @
51fb81e2
...
@@ -28,6 +28,7 @@ describe('annotator.config', function() {
...
@@ -28,6 +28,7 @@ describe('annotator.config', function() {
fakeSettings
.
annotations
=
sinon
.
stub
().
returns
(
null
);
fakeSettings
.
annotations
=
sinon
.
stub
().
returns
(
null
);
fakeSettings
.
query
=
sinon
.
stub
().
returns
(
null
);
fakeSettings
.
query
=
sinon
.
stub
().
returns
(
null
);
fakeSettings
.
configFuncSettingsFrom
=
sinon
.
stub
().
returns
({});
fakeSettings
.
configFuncSettingsFrom
=
sinon
.
stub
().
returns
({});
fakeSettings
.
isBrowserExtension
=
sinon
.
stub
().
returns
(
false
);
});
});
it
(
'gets the config.app setting'
,
function
()
{
it
(
'gets the config.app setting'
,
function
()
{
...
@@ -188,39 +189,38 @@ describe('annotator.config', function() {
...
@@ -188,39 +189,38 @@ describe('annotator.config', function() {
});
});
context
(
'when the client is injected by the browser extension'
,
function
()
{
context
(
'when the client is injected by the browser extension'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
'configure a browser extension client'
,
function
()
{
fakeSettings
.
annotations
.
returns
(
'SOME_ANNOTATION_ID'
);
fakeSettings
.
isBrowserExtension
.
returns
(
true
);
fakeSharedSettings
.
jsonConfigsFrom
.
returns
({
foo
:
'bar'
});
});
});
it
(
'ignores the host page config on chrome'
,
function
()
{
it
(
'still reads the config.app setting from the host page'
,
function
()
{
fakeSettings
.
app
.
returns
(
'chrome-extension://abcdef'
);
fakeSettings
.
app
.
returns
(
'SOME_APP_URL'
);
var
config
=
configFrom
(
fakeWindow
());
assert
.
equal
(
config
.
app
,
'chrome-extension://abcdef'
);
assert
.
equal
(
configFrom
(
fakeWindow
()).
app
,
fakeSettings
.
app
());
assert
.
equal
(
config
.
annotations
,
'SOME_ANNOTATION_ID'
);
assert
.
isUndefined
(
config
.
foo
);
});
});
it
(
'
ignores the host page config on firefox
'
,
function
()
{
it
(
'
still reads the config.query setting from the host page
'
,
function
()
{
fakeSettings
.
app
.
returns
(
'moz-extension://abcdef
'
);
fakeSettings
.
query
.
returns
(
'SOME_QUERY
'
);
var
config
=
configFrom
(
fakeWindow
());
assert
.
equal
(
configFrom
(
fakeWindow
()).
query
,
fakeSettings
.
query
());
});
assert
.
equal
(
config
.
app
,
'moz-extension://abcdef'
);
it
(
'still reads the config.annotations setting from the host page'
,
function
()
{
assert
.
equal
(
config
.
annotations
,
'SOME_ANNOTATION_ID'
);
fakeSettings
.
annotations
.
returns
(
'SOME_ANNOTATION_ID'
);
assert
.
isUndefined
(
config
.
foo
);
assert
.
equal
(
configFrom
(
fakeWindow
()).
annotations
,
fakeSettings
.
annotations
());
});
});
it
(
'ignores
the host page config on ed
ge'
,
function
()
{
it
(
'ignores
settings from JSON objects in the host pa
ge'
,
function
()
{
fakeS
ettings
.
app
.
returns
(
'ms-browser-extension://abcdef'
);
fakeS
haredSettings
.
jsonConfigsFrom
.
returns
({
foo
:
'bar'
}
);
var
config
=
configFrom
(
fakeWindow
());
assert
.
isUndefined
(
configFrom
(
fakeWindow
()).
foo
);
});
assert
.
equal
(
config
.
app
,
'ms-browser-extension://abcdef'
);
it
(
'ignores settings from the hypothesisConfig() function in the host page'
,
function
()
{
assert
.
equal
(
config
.
annotations
,
'SOME_ANNOTATION_ID'
);
fakeSettings
.
configFuncSettingsFrom
.
returns
({
foo
:
'bar'
});
assert
.
isUndefined
(
config
.
foo
);
assert
.
isUndefined
(
configFrom
(
fakeWindow
()).
foo
);
});
});
});
});
...
...
src/annotator/config/test/settings-test.js
View file @
51fb81e2
...
@@ -236,4 +236,39 @@ describe('annotation.config.settings', function() {
...
@@ -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