From 29b00ae0d6558c42f31cb3f1588f012ffb7e91c2 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 22 Dec 2015 17:16:31 -0500 Subject: [PATCH] Add tests for did-change-theme-color event --- atom/browser/api/atom_api_web_contents.cc | 12 +++++------- docs/api/web-contents.md | 16 ++++++++++++++++ docs/api/web-view-tag.md | 4 +++- spec/fixtures/pages/theme-color.html | 7 +++++++ spec/webview-spec.coffee | 7 +++++++ 5 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 spec/fixtures/pages/theme-color.html diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 05c2683b260a..461a66c4b2f1 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -490,13 +490,11 @@ void WebContents::MediaPaused() { } void WebContents::DidChangeThemeColor(SkColor theme_color) { - char themeColor[8] = { 0 }; - snprintf(themeColor, sizeof(themeColor), - "#%02X%02X%02X", - SkColorGetR(theme_color), - SkColorGetG(theme_color), - SkColorGetB(theme_color)); - Emit("did-change-theme-color", themeColor); + std::string hex_theme_color = base::StringPrintf("#%02X%02X%02X", + SkColorGetR(theme_color), + SkColorGetG(theme_color), + SkColorGetB(theme_color)); + Emit("did-change-theme-color", hex_theme_color); } void WebContents::DocumentLoadedInFrame( diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 7e41b02ae664..2057b515c025 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -235,6 +235,22 @@ Returns: Emitted when a result is available for [`webContents.findInPage`](web-contents.md#webcontentsfindinpage) request. +### Event: 'media-started-playing' + +Emitted when media starts playing. + +### Event: 'media-paused' + +Emitted when media is paused or done playing. + +### Event: 'did-change-theme-color' + +Emitted when a page's theme color changes. This is usually due to encountering a meta tag: + +```html + +``` + ## Instance Methods The `webContents` object has the following instance methods: diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 0eda48824636..0c79083c112d 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -647,4 +647,6 @@ Emitted when media is paused or done playing. Emitted when a page's theme color changes. This is usually due to encountering a meta tag: - +```html + +``` diff --git a/spec/fixtures/pages/theme-color.html b/spec/fixtures/pages/theme-color.html new file mode 100644 index 000000000000..57c49f337337 --- /dev/null +++ b/spec/fixtures/pages/theme-color.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/spec/webview-spec.coffee b/spec/webview-spec.coffee index c0578d05053b..d6c1a2de7b97 100644 --- a/spec/webview-spec.coffee +++ b/spec/webview-spec.coffee @@ -406,3 +406,10 @@ describe ' tag', -> webview.addEventListener 'did-finish-load', listener2 webview.src = "file://#{fixtures}/pages/content.html" document.body.appendChild webview + + describe 'did-change-theme-color event', -> + it 'emits when theme color changes', (done) -> + webview.addEventListener 'did-change-theme-color', (e) -> + done() + webview.src = "file://#{fixtures}/pages/theme-color.html" + document.body.appendChild webview