Merge lp:~abreu-alexandre/webbrowser-app/handle-theme-color-updates into lp:webbrowser-app

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 1377
Merged at revision: 1394
Proposed branch: lp:~abreu-alexandre/webbrowser-app/handle-theme-color-updates
Merge into: lp:webbrowser-app
Diff against target: 134 lines (+61/-13)
3 files modified
src/app/webcontainer/webapp-specific-page-metadata-collector.js (+13/-4)
tests/autopilot/webapp_container/tests/fake_servers.py (+30/-9)
tests/autopilot/webapp_container/tests/test_page_meta_collector.py (+18/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/webbrowser-app/handle-theme-color-updates
Reviewer Review Type Date Requested Status
Alberto Mardegan (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+288541@code.launchpad.net

Commit message

Handle live updates to theme color meta tag and reflect them in the top bar background color

Description of the change

Handle live updates to theme color meta tag and reflect them in the top bar background color

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alberto Mardegan (mardy) wrote :

LGTM.

review: Approve
1378. By Alexandre Abreu

flake8 issues

1379. By Alexandre Abreu

merge trunk

1380. By Alexandre Abreu

Remove duplicate import in container AP tests server

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webcontainer/webapp-specific-page-metadata-collector.js'
2--- src/app/webcontainer/webapp-specific-page-metadata-collector.js 2015-11-30 20:20:32 +0000
3+++ src/app/webcontainer/webapp-specific-page-metadata-collector.js 2016-04-04 15:28:49 +0000
4@@ -47,10 +47,19 @@
5 return false;
6 }
7
8- var detectors = [detectThemeColorMetaInformation, detectManifestMetaInformation]
9- for (var i in detectors) {
10- if (detectors[i]()) {
11- break;
12+ function extractWebAppMetaInfo() {
13+ var detectors = [detectThemeColorMetaInformation, detectManifestMetaInformation]
14+ for (var i in detectors) {
15+ if (detectors[i]()) {
16+ break;
17+ }
18 }
19 }
20+ extractWebAppMetaInfo();
21+
22+ var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
23+ var observer = new MutationObserver(function(mutations) {
24+ extractWebAppMetaInfo();
25+ });
26+ observer.observe(document, {childList: true, subtree: true, attributes: true });
27 })();
28
29=== modified file 'tests/autopilot/webapp_container/tests/fake_servers.py'
30--- tests/autopilot/webapp_container/tests/fake_servers.py 2016-03-10 14:21:43 +0000
31+++ tests/autopilot/webapp_container/tests/fake_servers.py 2016-04-04 15:28:49 +0000
32@@ -159,29 +159,43 @@
33 "theme_color": "#FF0000"
34 } """
35
36- def theme_color_content(self, color, with_manifest=False):
37+ def theme_color_content(self,
38+ color,
39+ with_manifest=False,
40+ delayed_color_update=''):
41 color_content = ''
42 if color:
43 color_content = """
44 <meta name=\"theme-color\" content=\"{}\"></meta>
45 """.format(color)
46+
47 manifest_content = ''
48 if with_manifest:
49 manifest_content = "<link rel=\"manifest\" href=\"manifest.json\">"
50
51+ delayed_color_code = ''
52+ if len(delayed_color_update) != 0:
53+ delayed_color_code = """
54+setTimeout(function() {
55+ var e=document.head.querySelector('meta[name="theme-color"]');
56+ e.content = '%s';
57+}, 2000)""" % delayed_color_update
58+
59 return """
60 <html>
61 <head>
62 {}
63 {}
64+
65+<script>
66+{}
67+</script>
68 <title>theme-color</title>
69-<script>
70-</script>
71 </head>
72 <body>
73 </body>
74 </html>
75- """.format(color_content, manifest_content)
76+ """.format(color_content, manifest_content, delayed_color_code)
77
78 def open_close_content(self):
79 return """
80@@ -257,16 +271,23 @@
81 self.send_response(200)
82 self.serve_content(self.manifest_json_content())
83 elif self.path.startswith('/theme-color/'):
84- args = self.path[len('/theme-color/'):]
85+ q = urllib.parse.parse_qs(
86+ urllib.parse.urlparse(
87+ self.path).query)
88 self.send_response(200)
89 color = ''
90- if args.startswith('?color='):
91- color = args[len('?color='):]
92+ if 'color' in q:
93+ color = q['color'][0]
94+ color_update = ''
95+ if 'delaycolorupdate' in q:
96+ color_update = q['delaycolorupdate'][0]
97 with_manifest = False
98- if args.startswith('?manifest='):
99+ if 'manifest' in q and q['manifest'][0] == 'true':
100 with_manifest = True
101 self.send_response(200)
102- self.serve_content(self.theme_color_content(color, with_manifest))
103+ self.serve_content(
104+ self.theme_color_content(
105+ color, with_manifest, color_update))
106 elif self.path.startswith('/saml/'):
107 args = self.path[len('/saml/'):]
108 loopCount = 0
109
110=== modified file 'tests/autopilot/webapp_container/tests/test_page_meta_collector.py'
111--- tests/autopilot/webapp_container/tests/test_page_meta_collector.py 2015-12-02 18:01:18 +0000
112+++ tests/autopilot/webapp_container/tests/test_page_meta_collector.py 2016-04-04 15:28:49 +0000
113@@ -47,3 +47,21 @@
114 self.assertThat(
115 lambda: str(chrome_base.backgroundColor),
116 Eventually(Equals("Color(255, 0, 0, 255)")))
117+
118+ def test_track_theme_color_live_updates(self):
119+ args = ['--enable-addressbar']
120+ self.launch_webcontainer_app_with_local_http_server(
121+ args,
122+ '/theme-color/?color=red&delaycolorupdate=black')
123+ self.get_webcontainer_window().visible.wait_for(True)
124+
125+ chrome_base = self.app.wait_select_single(
126+ objectName="chromeBase")
127+
128+ self.assertThat(
129+ lambda: str(chrome_base.backgroundColor),
130+ Eventually(Equals("Color(255, 0, 0, 255)")))
131+
132+ self.assertThat(
133+ lambda: str(chrome_base.backgroundColor),
134+ Eventually(Equals("Color(0, 0, 0, 255)")))

Subscribers

People subscribed via source and target branches

to status/vote changes: