Add 'loading-state-changed' event for BrowserWindow.

It's required for testing the BrowserWindow class.
This commit is contained in:
Cheng Zhao 2013-08-29 11:47:07 +08:00
Родитель e00d3d4b37
Коммит 34e1800716
5 изменённых файлов: 32 добавлений и 2 удалений

Просмотреть файл

@ -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'