зеркало из https://github.com/electron/electron.git
Add 'loading-state-changed' event for BrowserWindow.
It's required for testing the BrowserWindow class.
This commit is contained in:
Родитель
e00d3d4b37
Коммит
34e1800716
|
@ -56,6 +56,12 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
|
|||
*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) {
|
||||
*prevent_default = Emit("close");
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ class Window : public EventEmitter,
|
|||
// Implementations of NativeWindowObserver.
|
||||
virtual void OnPageTitleUpdated(bool* prevent_default,
|
||||
const std::string& title) OVERRIDE;
|
||||
virtual void OnLoadingStateChanged(bool is_loading) OVERRIDE;
|
||||
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
|
||||
virtual void OnWindowClosed() OVERRIDE;
|
||||
virtual void OnWindowBlur() OVERRIDE;
|
||||
|
|
|
@ -17,7 +17,7 @@ class NativeWindowObserver {
|
|||
virtual void OnPageTitleUpdated(bool* prevent_default,
|
||||
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) {}
|
||||
|
||||
// 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.
|
||||
|
||||
### Event: 'loading-state-changed'
|
||||
|
||||
* `event` Event
|
||||
* `isLoading` Boolean
|
||||
|
||||
Emitted when the window is starting or is done loading a page.
|
||||
|
||||
### Event: 'close'
|
||||
|
||||
* `event` Event
|
||||
|
@ -325,4 +332,4 @@ Reloads current window.
|
|||
|
||||
### BrowserWindow.reloadIgnoringCache()
|
||||
|
||||
Reloads current window and ignores cache.
|
||||
Reloads current window and ignores cache.
|
||||
|
|
|
@ -31,3 +31,19 @@ describe 'window module', ->
|
|||
assert.equal String(content), 'close'
|
||||
done()
|
||||
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'
|
||||
|
|
Загрузка…
Ссылка в новой задаче