24
Building Testable Chrome Extensions Steven Foote Seth McLaughlin 08.18.14

Building testable chrome extensions

Embed Size (px)

DESCRIPTION

Chrome Extensions are fun to build and very powerful, thanks to the expansive API Google provides. This talk will explore techniques for structuring and testing your extension projects, using tools such as Grunt, Browserify and Venus.js. A quick refresher of major extension development concepts will be also be reviewed.

Citation preview

Page 1: Building testable chrome extensions

Building Testable!Chrome Extensions!

!!!!!!!

Steven Foote!Seth McLaughlin!

08.18.14

Page 2: Building testable chrome extensions
Page 3: Building testable chrome extensions
Page 4: Building testable chrome extensions

http://amzn.to/XvgLq4

Page 5: Building testable chrome extensions

Chrome Extensions are SWEET!● Extend the world's most popular browser with new features.!● Mini applications that run in Chrome - Chrome is like an OS

Page 6: Building testable chrome extensions
Page 7: Building testable chrome extensions

Evernote

Page 8: Building testable chrome extensions
Page 9: Building testable chrome extensions

Tracker

Page 10: Building testable chrome extensions
Page 11: Building testable chrome extensions
Page 12: Building testable chrome extensions

Chrome Extensions are fun to build

HTML / JS / CSS Awesome APIs

Evergreen Browser

Page 13: Building testable chrome extensions

Chrome API Basics● Content Scripts!● Background Scripts!● Permissions

Page 14: Building testable chrome extensions

Chrome API BasicsPage Actions!!!!!Browser Actions

Page 15: Building testable chrome extensions

Chrome API BasicsContext Menus ! Omnibox

Page 16: Building testable chrome extensions

Content ScriptBackground Page

(1 instance)Content ScriptContent Script

(1:1 with tabs)

chrome.runtime.sendMessage()

Local Storage (specific to extension)

save and load data

Page 17: Building testable chrome extensions

Introducing WebberNote

Page 18: Building testable chrome extensions

DEMO!

https://github.com/sethmcl/webberNote

Page 19: Building testable chrome extensions

Tips for organizing and testing code● Use commonJS modules (browserify)!● Use grunt to make building easy!● Mock chrome.* APIs with chrome-mock!● Test code in browser with Venus.js & Mocha

Page 20: Building testable chrome extensions

chrome.runtime.sendMessage()e

window.localStorage

contentScript.js background.js

Page

StoreClient

domchrome.tabs.query()

Store

MessageRouter

ContextMenu

MessageRouter

Page 21: Building testable chrome extensions

WebberNote directory structuresrc ├── _locales ├── images ├── lib ├── manifest.json ├── options.html ├── popup.html ├── scripts │ ├── background.js │ ├── contentScript.js │ ├── options.js │ └── popup.js └── styles

Page 22: Building testable chrome extensions

Introducing Chrome-Mocknpm install chrome-mock !Generated from chromium *.json files!https://github.com/sethmcl/chrome-mock

Page 23: Building testable chrome extensions

DEMO!!!

with code this time!

https://github.com/sethmcl/webberNote

Page 24: Building testable chrome extensions

ResourcesChrome API Docs!https://developer.chrome.com/extensions/api_index !Chrome API mocks!https://github.com/sethmcl/chrome-mock !WebberNote source code!https://github.com/sethmcl/webbernote

Browserify!http://browserify.org/ !Venus.js!http://www.venusjs.org/ !Grunt!http://gruntjs.com/

Steven Foote!https://www.linkedin.com/in/stevenmfoote !

Seth McLaughlin!https://www.linkedin.com/in/sethmclaughlin