Add 'loading-state-changed' event for BrowserWindow.
It's required for testing the BrowserWindow class.
This commit is contained in:
parent
e00d3d4b37
commit
34e1800716
5 changed files with 32 additions and 2 deletions
|
@ -56,6 +56,12 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
|
||||||
*prevent_default = Emit("page-title-updated", &args);
|
*prevent_default = Emit("page-title-updated", &args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::OnLoadingStateChanged(bool is_loading) {
|
||||||
|
base::ListValue args;
|
||||||
|
args.AppendBoolean(is_loading);
|
||||||
|
Emit("loading-state-changed", &args);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::WillCloseWindow(bool* prevent_default) {
|
void Window::WillCloseWindow(bool* prevent_default) {
|
||||||
*prevent_default = Emit("close");
|
*prevent_default = Emit("close");
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Window : public EventEmitter,
|
||||||
// Implementations of NativeWindowObserver.
|
// Implementations of NativeWindowObserver.
|
||||||
virtual void OnPageTitleUpdated(bool* prevent_default,
|
virtual void OnPageTitleUpdated(bool* prevent_default,
|
||||||
const std::string& title) OVERRIDE;
|
const std::string& title) OVERRIDE;
|
||||||
|
virtual void OnLoadingStateChanged(bool is_loading) OVERRIDE;
|
||||||
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
|
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
|
||||||
virtual void OnWindowClosed() OVERRIDE;
|
virtual void OnWindowClosed() OVERRIDE;
|
||||||
virtual void OnWindowBlur() OVERRIDE;
|
virtual void OnWindowBlur() OVERRIDE;
|
||||||
|
|
|
@ -17,7 +17,7 @@ class NativeWindowObserver {
|
||||||
virtual void OnPageTitleUpdated(bool* prevent_default,
|
virtual void OnPageTitleUpdated(bool* prevent_default,
|
||||||
const std::string& title) {}
|
const std::string& title) {}
|
||||||
|
|
||||||
// Called when the window is starting or is done loading a resource.
|
// Called when the window is starting or is done loading a page.
|
||||||
virtual void OnLoadingStateChanged(bool is_loading) {}
|
virtual void OnLoadingStateChanged(bool is_loading) {}
|
||||||
|
|
||||||
// Called when the window is gonna closed.
|
// Called when the window is gonna closed.
|
||||||
|
|
|
@ -45,6 +45,13 @@ Creates a new `BrowserWindow` with native properties set by the `options`. Usual
|
||||||
|
|
||||||
Emitted when the document changed its title, calling `event.preventDefault()` would prevent the native window's title to change.
|
Emitted when the document changed its title, calling `event.preventDefault()` would prevent the native window's title to change.
|
||||||
|
|
||||||
|
### Event: 'loading-state-changed'
|
||||||
|
|
||||||
|
* `event` Event
|
||||||
|
* `isLoading` Boolean
|
||||||
|
|
||||||
|
Emitted when the window is starting or is done loading a page.
|
||||||
|
|
||||||
### Event: 'close'
|
### Event: 'close'
|
||||||
|
|
||||||
* `event` Event
|
* `event` Event
|
||||||
|
|
|
@ -31,3 +31,19 @@ describe 'window module', ->
|
||||||
assert.equal String(content), 'close'
|
assert.equal String(content), 'close'
|
||||||
done()
|
done()
|
||||||
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close.html')
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close.html')
|
||||||
|
|
||||||
|
describe 'BrowserWindow.loadUrl(url)', ->
|
||||||
|
it 'should emit loading-state-changed event', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
count = 0
|
||||||
|
w.on 'loading-state-changed', (event, isLoading) ->
|
||||||
|
if count == 0
|
||||||
|
assert.equal isLoading, true
|
||||||
|
else if count == 1
|
||||||
|
assert.equal isLoading, false
|
||||||
|
done()
|
||||||
|
else
|
||||||
|
assert false
|
||||||
|
|
||||||
|
++count
|
||||||
|
w.loadUrl 'about:blank'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue