Skip to content

Commit

Permalink
Merge pull request #158 from jhen0409/patch-4
Browse files Browse the repository at this point in the history
Update Electron mock
  • Loading branch information
zalmoxisus authored Jul 8, 2016
2 parents 62f0af5 + 08f8d39 commit 51c2516
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 29 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ environment:
- nodejs_version: '4'

cache:
- node_modules
- node_modules -> package.json

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"webpack": "^1.12.2"
},
"dependencies": {
"codemirror": "^5.16.0",
"jsan": "^3.1.1",
"lodash": "^4.2.0",
"react": "^15.1.0",
Expand Down
8 changes: 3 additions & 5 deletions src/browser/extension/background/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export default function createMenu() {
});
}

if (chrome.contextMenus) {
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
openDevToolsWindow(menuItemId);
});
}
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
openDevToolsWindow(menuItemId);
});
50 changes: 34 additions & 16 deletions src/browser/extension/electronMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,44 @@ if (
create() {},
clear() {}
};
chrome.contextMenus = {
onClicked: {
addListener() {}
},
};
}

if (window.isElectron) {
chrome.storage.local = {
set(obj, callback) {
Object.keys(obj).forEach(key => {
localStorage.setItem(key, obj[key]);
});
if (callback) {
callback();
}
},
get(obj, callback) {
const result = {};
Object.keys(obj).forEach(key => {
result[key] = localStorage.getItem(key) || obj[key];
});
if (callback) {
callback(result);
if (!chrome.storage.local) {
chrome.storage.local = {
set(obj, callback) {
Object.keys(obj).forEach(key => {
localStorage.setItem(key, obj[key]);
});
if (callback) {
callback();
}
},
get(obj, callback) {
const result = {};
Object.keys(obj).forEach(key => {
result[key] = localStorage.getItem(key) || obj[key];
});
if (callback) {
callback(result);
}
}
};
}
// Avoid error: chrome.runtime.sendMessage is not supported responseCallback
const originSendMessage = chrome.runtime.sendMessage;
chrome.runtime.sendMessage = function() {
if (process.env.NODE_ENV === 'development') {
return originSendMessage(...arguments);
}
if (typeof arguments[arguments.length - 1] === 'function') {
Array.prototype.pop.call(arguments);
}
return originSendMessage(...arguments);
};
}
36 changes: 30 additions & 6 deletions test/electron/devpanel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('DevTools panel for Electron', function() {
})
.forBrowser('electron')
.build();
await this.driver.manage().timeouts().setScriptTimeout(10000);
});

after(async () => {
Expand All @@ -32,12 +33,25 @@ describe('DevTools panel for Electron', function() {
expect(await this.driver.getCurrentUrl())
.toMatch(/chrome-devtools:\/\/devtools\/bundled\/inspector.html/);

await delay(1000); // wait loading of redux devtools
const id = await this.driver.executeScript(function() {
const tabs = WebInspector.inspectorView._tabbedPane._tabs;
const lastPanelId = tabs[tabs.length - 1].id;
WebInspector.inspectorView.showPanel(lastPanelId);
return lastPanelId;
await this.driver.manage().timeouts().pageLoadTimeout(5000);

const id = await this.driver.executeAsyncScript(function(callback) {
let attempts = 5;
function showReduxPanel() {
if (attempts === 0) {
return callback('Redux panel not found');
}
const tabs = WebInspector.inspectorView._tabbedPane._tabs;
const idList = tabs.map(tab => tab.id);
const reduxPanelId = 'chrome-extension://redux-devtoolsRedux';
if (idList.indexOf(reduxPanelId) !== -1) {
WebInspector.inspectorView.showPanel(reduxPanelId);
return callback(reduxPanelId);
}
attempts--;
setTimeout(showReduxPanel, 500);
}
showReduxPanel();
});
expect(id).toBe('chrome-extension://redux-devtoolsRedux');

Expand Down Expand Up @@ -68,4 +82,14 @@ describe('DevTools panel for Electron', function() {
Object.keys(switchMonitorTests).forEach(description =>
it(description, switchMonitorTests[description].bind(this))
);

it('should be no logs in console of main window', async () => {
const handles = await this.driver.getAllWindowHandles();
await this.driver.switchTo().window(handles[1]); // Change to main window

expect(await this.driver.getTitle()).toBe('Electron Test');

const logs = await this.driver.manage().logs().get(webdriver.logging.Type.BROWSER);
expect(logs).toEqual([]);
});
});
2 changes: 1 addition & 1 deletion webpack/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const baseConfig = (params) => ({
remote: [ `${extpath}window/remote` ],
devpanel: [ electronMock, `${extpath}devpanel/index` ],
devtools: [ `${extpath}devtools/index` ],
content: [ `${extpath}inject/contentScript` ],
content: [ electronMock, `${extpath}inject/contentScript` ],
pagewrap: [ `${extpath}inject/pageScriptWrap` ],
inject: [ `${extpath}inject/index` ],
...params.inputExtra
Expand Down

0 comments on commit 51c2516

Please sign in to comment.